
/*
    Software License

    Copyright (C) 2021-05-24  Xoronos

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, version 3.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

/*
    Liabilities

    The software is provided "AS IS" without any warranty of any kind, either expressed,
    implied, or statutory, including, but not limited to, any warranty that the software
    will conform to specifications, any implied warranties of merchantability, fitness
    for a particular purpose, and freedom from infringement, and any warranty that the
    documentation will conform to the software, or any warranty that the software will
    be error free.

    In no event shall Xoronos be liable for any damages, including, but not limited to,
    direct, indirect, special or consequential damages, arising out of, resulting from,
    or in any way connected with this software, whether or not based upon warranty,
    contract, tort, or otherwise, whether or not injury was sustained by persons or
    property or otherwise, and whether or not loss was sustained from, or arose out of
    the results of, or use of, the software or services provided hereunder.

    To request the provided software under a different license you can contact us at
    support@xoronos.com
*/

#include "test_crypto.h"

#if !defined( XRN_MAX_STATE_SIZE )
#define XRN_MAX_STATE_SIZE (XNBITS-1)
#endif
#define IMPOSE_MAX_STATE_SIZE 0

void generate_file_matrix( XBIT_TYPE known_ob,
                           int base_max_value,
                           int offset_value,
                           char fname_input_file[256],
                           char fname_xgenesis_file[256],
                           char fname_xrn_matrix[256], xrn_crypto_extra_settings_t settings
 )
{

    FILE *fpi;                  // input file
    FILE *fpm;                  // matrix
    FILE *fpob;                 // origin base
    uint8_t c;
    xnum_t cob, cos;
    xgenesis_base_t *ob;
    xrn_matrix_t *xm;
    int file_size, i;
    uint8_t mining_mode;

    // generate a random file
    file_size =
        ( int ) ( ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 -
                    2 ) ) * ( rand(  ) % base_max_value + offset_value ) +
        ( rand(  ) % ( int ) ( ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 ) ) );

    fpi = fopen( fname_input_file, "wb" );
    for ( i = 0; i < file_size; i++ ) {
        c = ( uint8_t ) ( rand(  ) % 256 );
        fwrite( &c, sizeof( char ), 1, fpi );
    }

    fclose( fpi );

    // generate origin base

    mining_mode = 0;
    fpob = fopen( fname_xgenesis_file, "wb" );
    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    if ( !known_ob ) {
        xrn_mine_random_wrapper( fpob, ( float ) 0.1, 50000, mining_mode, NULL, settings );
    } else {

        xgenesis_base_init( ob );

    }

    fclose( fpob );

    // generate xoron matrix

    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    fpm = fopen( fname_xrn_matrix, "wb" );
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, fpm, settings );
    free( xm );
    fclose( fpm );

    return;

}

void generate_file_matrix_key_binomial( XBIT_TYPE known_ob,
                                        int base_max_value,
                                        int offset_value,
                                        char fname_input_file[256],
                                        char fname_xgenesis_file[256],
                                        char fname_xrn_matrix[256],
                                        char fname_key_binomial[256],
                                        char fname_key_monomial[256], xrn_crypto_extra_settings_t settings
 )
{

    FILE *fpi;                  // input file
    FILE *fpkpr;                // key monomial
    FILE *fpkpu;                // key binomial
    FILE *fpm;                  // matrix
    FILE *fpob;                 // origin base
    xnum_t cob, cos;
    uint8_t c;
    xgenesis_base_t *ob;
    xrn_matrix_t *xm;
    int file_size, i;
    xmonomial_key_t monomial;
    xbinomial_key_t binomial;
    xstart_point_t start;
    uint8_t mining_mode;

    // generate a random file

    file_size =
        ( int ) ( ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 -
                    2 ) ) * ( int ) ( ( rand(  ) % base_max_value + offset_value ) ) +
        ( rand(  ) % ( int ) ( ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 ) ) );

    fpi = fopen( fname_input_file, "wb" );
    for ( i = 0; i < file_size; i++ ) {
        c = ( uint8_t ) ( rand(  ) % 256 );
        fwrite( &c, sizeof( char ), 1, fpi );
    }

    fclose( fpi );

    // generate origin base

    mining_mode = 0;
    fpob = fopen( fname_xgenesis_file, "wb" );
    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    if ( !known_ob ) {
        xrn_mine_random_wrapper( fpob, ( float ) 0.1, 50000, mining_mode, NULL, settings );
    } else {

        xgenesis_base_init( ob );

    }

    fclose( fpob );

    // generate xoron matrix

    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    fpm = fopen( fname_xrn_matrix, "wb" );
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, fpm, settings );
    fclose( fpm );

    // generate key

    xrn_initialize_rnd_num( &start.start );
    xrn_initialize_rnd_num( &monomial.distance );
    xrn_make_binomial_key( xm, start, monomial, &binomial, settings );

    fpkpr = fopen( fname_key_monomial, "wb" );
    xrn_dump_monomial_key( monomial, fpkpr, settings );
    fclose( fpkpr );

    fpkpu = fopen( fname_key_binomial, "wb" );
    xrn_dump_binomial_key( binomial, fpkpu, settings );
    fclose( fpkpu );
    free( xm );

    return;

}

void generate_file_matrix_key_monomial( XBIT_TYPE known_ob,
                                        int base_max_value,
                                        int offset_value,
                                        char fname_input_file[256],
                                        char fname_xgenesis_file[256],
                                        char fname_xrn_matrix[256],
                                        char fname_key[256], xrn_crypto_extra_settings_t settings
 )
{

    FILE *fpi;                  // input file
    FILE *fpk;                  // key
    FILE *fpm;                  // matrix
    FILE *fpob;                 // origin base
    xnum_t cob, cos;
    uint8_t c;
    xgenesis_base_t *ob;
    xrn_matrix_t *xm;
    int file_size, i;
    xmonomial_key_t monomial;
    uint8_t mining_mode;

    // generate a random file
    file_size =
        ( int ) ( ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 -
                    2 ) ) * ( int ) ( ( rand(  ) % base_max_value + offset_value ) ) +
        ( rand(  ) % ( int ) ( ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 ) ) );

    fpi = fopen( fname_input_file, "wb" );
    for ( i = 0; i < file_size; i++ ) {
        c = ( uint8_t ) ( rand(  ) % 256 );
        fwrite( &c, sizeof( char ), 1, fpi );
    }

    fclose( fpi );

    // generate origin base

    mining_mode = 0;
    fpob = fopen( fname_xgenesis_file, "wb" );
    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    if ( !known_ob ) {
        xrn_mine_random_wrapper( fpob, ( float ) 0.1, 50000, mining_mode, NULL, settings );
    } else {

        xgenesis_base_init( ob );

    }

    fclose( fpob );

    // generate xoron matrix

    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    fpm = fopen( fname_xrn_matrix, "wb" );
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    xrn_dump_matrix( xm, fpm, settings );
    fclose( fpm );
    free( ob );

    // generate key

    xrn_make_monomial_key( &monomial, settings );

    fpk = fopen( fname_key, "wb" );
    xrn_dump_monomial_key( monomial, fpk, settings );
    fclose( fpk );
    free( xm );

    return;

}

int test_encrypt_symmetric(
 )
{

    int error, crc_bytes;

    FILE *fpi;                  // input file
    FILE *fpo;                  // output file
    FILE *fpk;                  // key
    FILE *fpm;                  // matrix

    int base_max_value, offset_value, cnt0, cnt1;
    char ch1;
    char ch2;
    char fname_input_file[256];
    char fname_xgenesis_file[256];
    char fname_xrn_matrix[256];
    char fname_key[256];
    char fname_output_file_enc[256];
    char fname_output_file_dec[256];
    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    base_max_value = 5;
    offset_value = 0;

    strcpy( fname_input_file, "../cache/to_remove_load_symmetric_all_file.txt" );
    strcpy( fname_xgenesis_file, "../cache/to_remove_load_symmetric_all_ob.txt" );
    strcpy( fname_key, "../cache/to_remove_load_symmetric_all_key.txt" );
    strcpy( fname_xrn_matrix, "../cache/to_remove_load_symmetric_all_xm.txt" );
    strcpy( fname_output_file_enc, "../cache/to_remove_load_symmetric_output_enc.txt" );
    strcpy( fname_output_file_dec, "../cache/to_remove_load_symmetric_output_dec.txt" );

    error = 0;

    generate_file_matrix_key_monomial( 1, base_max_value, offset_value,
                                       fname_input_file, fname_xgenesis_file, fname_xrn_matrix, fname_key,
                                       settings );

    // encrypt

    fpi = fopen( fname_input_file, "rb" );
    fpm = fopen( fname_xrn_matrix, "rb" );
    fpk = fopen( fname_key, "rb" );
    fpo = fopen( fname_output_file_enc, "wb" );

    if ( xrn_encrypt_symmetric_wrapper( fpi, fpm, fpk, fpo, settings ) != 0 ) {
        error = 1;
    }

    fclose( fpi );
    fclose( fpm );
    fclose( fpk );
    fclose( fpo );

    // decrypt

    fpi = fopen( fname_output_file_enc, "rb" );
    fpm = fopen( fname_xrn_matrix, "rb" );
    fpk = fopen( fname_key, "rb" );
    fpo = fopen( fname_output_file_dec, "wb" );

    if ( xrn_decrypt_symmetric_wrapper( fpi, fpm, fpk, fpo, settings ) != 0 ) {
        error = 1;
    }

    fclose( fpi );
    fclose( fpm );
    fclose( fpk );
    fclose( fpo );

    // compare the two files

    fpi = fopen( fname_input_file, "rb" );
    fpo = fopen( fname_output_file_dec, "rb" );
    do {
        // Input character from both files
        cnt0 = ( int ) fread( &ch1, sizeof( uint8_t ), 1, fpi );
        cnt1 = ( int ) fread( &ch2, sizeof( uint8_t ), 1, fpo );
        error = ( ( ch1 != ch2 ) || ( cnt0 != cnt1 ) ) || error;

    } while ( cnt0 != 0 && cnt1 != 0 );

    fclose( fpi );
    fclose( fpo );

    remove( fname_input_file );
    remove( fname_xgenesis_file );
    remove( fname_xrn_matrix );
    remove( fname_key );
    remove( fname_output_file_enc );
    remove( fname_output_file_dec );

    if ( error != 0 ) {
        return 1;
    }

    return 0;

}

int test_encrypt_asymmetric(
 )
{

    int error, cnt0, cnt1, crc_bytes;

    FILE *fpi;                  // input file
    FILE *fpo;                  // output file
    FILE *fpk;                  // key
    FILE *fpm;                  // matrix

    int base_max_value, offset_value;
    char ch1;
    char ch2;
    char fname_input_file[256];
    char fname_xgenesis_file[256];
    char fname_xrn_matrix[256];
    char fname_key_monomial[256];
    char fname_key_binomial[256];
    char fname_output_file_enc[256];
    char fname_output_file_dec[256];
    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    base_max_value = 3;
    offset_value = 5;

    strcpy( fname_input_file, "../cache/to_remove_load_block_symmetric_all_file.txt" );
    strcpy( fname_xgenesis_file, "../cache/to_remove_load_block_symmetric_all_ob.txt" );
    strcpy( fname_key_binomial, "../cache/to_remove_load_block_symmetric_all_key_binomial.txt" );
    strcpy( fname_key_monomial, "../cache/to_remove_load_block_symmetric_all_key_monomial.txt" );
    strcpy( fname_xrn_matrix, "../cache/to_remove_load_block_symmetric_all_xm.txt" );
    strcpy( fname_output_file_enc, "../cache/to_remove_load_block_symmetric_output_enc.txt" );
    strcpy( fname_output_file_dec, "../cache/to_remove_load_block_symmetric_output_dec.txt" );

    error = 0;

    generate_file_matrix_key_binomial( 1, base_max_value, offset_value,
                                       fname_input_file, fname_xgenesis_file,
                                       fname_xrn_matrix, fname_key_binomial, fname_key_monomial, settings );

    // encrypt

    fpi = fopen( fname_input_file, "rb" );
    fpm = fopen( fname_xrn_matrix, "rb" );
    fpk = fopen( fname_key_binomial, "rb" );
    fpo = fopen( fname_output_file_enc, "wb" );
    if ( xrn_encrypt_asymmetric_wrapper( fpi, fpm, fpk, fpo, settings ) != 0 ) {
        remove( fname_input_file );
        remove( fname_xgenesis_file );
        remove( fname_xrn_matrix );
        remove( fname_key_monomial );
        remove( fname_key_binomial );
        remove( fname_output_file_enc );
        remove( fname_output_file_dec );
        error = 1;
    }

    fclose( fpi );
    fclose( fpm );
    fclose( fpk );
    fclose( fpo );

    // decrypt

    fpi = fopen( fname_output_file_enc, "rb" );
    fpm = fopen( fname_xrn_matrix, "rb" );
    fpk = fopen( fname_key_monomial, "rb" );
    fpo = fopen( fname_output_file_dec, "wb" );

    if ( xrn_decrypt_asymmetric_wrapper( fpi, fpm, fpk, fpo, settings ) != 0 ) {

        remove( fname_input_file );
        remove( fname_xgenesis_file );
        remove( fname_xrn_matrix );
        remove( fname_key_monomial );
        remove( fname_key_binomial );
        remove( fname_output_file_enc );
        remove( fname_output_file_dec );

        error = 1;
    }

    fclose( fpi );
    fclose( fpm );
    fclose( fpk );
    fclose( fpo );

    // compare the two files

    fpi = fopen( fname_input_file, "rb" );
    fpo = fopen( fname_output_file_dec, "rb" );

    do {
        // Input character from both files
        cnt0 = ( int ) fread( &ch1, sizeof( uint8_t ), 1, fpi );
        cnt1 = ( int ) fread( &ch2, sizeof( uint8_t ), 1, fpo );
        error = ( ( ch1 != ch2 ) || ( cnt0 != cnt1 ) ) || error;

    } while ( cnt0 != 0 && cnt1 != 0 );

    fclose( fpi );
    fclose( fpo );

    remove( fname_input_file );
    remove( fname_xgenesis_file );
    remove( fname_xrn_matrix );
    remove( fname_key_monomial );
    remove( fname_key_binomial );
    remove( fname_output_file_enc );
    remove( fname_output_file_dec );

    if ( error != 0 ) {
        return 1;
    }

    return 0;

}

int test_encrypt_split_join_bytes(
 )
{

    int error, crc_bytes;

    uint8_t *stri0, *stri1;     // input file
    uint8_t *stro0, *stro1;     // output file
    uint64_t stri_len0, stri_len1;      // input file
    uint64_t stro_len0, stro_len1;      // output file
    uint64_t i;
    xrn_lib_xtype_t type;

    uint64_t base_max_value, offset_value;
    uint64_t encoded_bytes_challenge, encoded_bytes_solution, decoded_bytes;
    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 3 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    base_max_value = 5;
    offset_value = 0;

    // create random bytes
    stri_len0 =
        ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 -
          2 ) * ( ( uint64_t ) rand(  ) % base_max_value + offset_value ) +
        ( ( uint64_t ) rand(  ) % ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 ) ) +
        ( uint64_t ) ( rand(  ) % 50 );

    stri0 = ( uint8_t * ) malloc( stri_len0 * sizeof( uint8_t ) );

    for ( i = 0; i < stri_len0; i++ ) {
        stri0[i] = ( uint8_t ) rand(  ) % 256;
    }

    type = c_challenge;

    // encrypt

    xrn_estimate_split_bytes_length( type, stri_len0, &stro_len0, &stro_len1, settings );
    stro0 = ( uint8_t * ) malloc( stro_len0 * sizeof( uint8_t ) );
    stro1 = ( uint8_t * ) malloc( stro_len1 * sizeof( uint8_t ) );
    if ( xrn_split_bytes_wrapper( stri0, stri_len0, stro0, stro_len0, &encoded_bytes_challenge,
                                  stro1, stro_len1, &encoded_bytes_solution, settings ) != 0 ) {
        free( stro0 );
        free( stro1 );
        free( stri0 );
        return 1;
    }

    // decrypt

    xrn_estimate_join_bytes_length( stro_len0, &stri_len1, settings );

    stri1 = ( uint8_t * ) malloc( stri_len1 * sizeof( uint8_t ) );

    if ( xrn_join_bytes_wrapper
         ( stro0, stro_len0, stro1, stro_len1, stri1, stri_len1, &decoded_bytes, settings ) != 0 ) {
        free( stro0 );
        free( stro1 );
        free( stri0 );
        free( stri1 );
        return 1;
    }

    // compare the two files
    error = 0;

    for ( i = 0; ( i < stri_len0 ); i++ ) {

        error = ( stri0[i] != stri1[i] ) || error;
    }

    free( stro0 );
    free( stro1 );
    free( stri0 );
    free( stri1 );

    if ( error != 0 ) {
        return 1;
    }

    return 0;

}

int test_encrypt_split_join(
 )
{

    int error, crc_bytes, file_size, i;

    FILE *fpi0, *fpi1;          // input file
    FILE *fpo0, *fpo1;          // output file

    int base_max_value, offset_value, cnt0, cnt1;
    char ch1;
    char ch2;
    char fname_input_file[256];
    char fname_output_file_enc0[256];
    char fname_output_file_enc1[256];
    char fname_output_file_dec[256];
    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 3 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    base_max_value = 5;
    offset_value = 5;

    strcpy( fname_input_file, "../cache/to_remove_load_symmetric_all_file_join_split.txt" );
    strcpy( fname_output_file_enc0, "../cache/to_remove_load_symmetric_output_enc_join_split0.txt" );
    strcpy( fname_output_file_enc1, "../cache/to_remove_load_symmetric_output_enc_join_split1.txt" );
    strcpy( fname_output_file_dec, "../cache/to_remove_load_symmetric_output_dec_join_split.txt" );

    error = 0;

    // generate a random file

    file_size =
        ( int ) ( ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 -
                    2 ) ) * ( rand(  ) % base_max_value + offset_value ) +
        ( rand(  ) % ( int ) ( ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 ) ) );

    fpi0 = fopen( fname_input_file, "wb" );
    for ( i = 0; i < file_size; i++ ) {
        ch1 = ( char ) ( rand(  ) % 256 );
        fwrite( &ch1, sizeof( char ), 1, fpi0 );
    }

    fclose( fpi0 );

    // encrypt

    fpi0 = fopen( fname_input_file, "rb" );
    fpo0 = fopen( fname_output_file_enc0, "wb" );
    fpo1 = fopen( fname_output_file_enc1, "wb" );

    if ( xrn_split_wrapper( fpi0, fpo0, fpo1, settings ) != 0 ) {
        return 1;
    }

    fclose( fpi0 );
    fclose( fpo0 );
    fclose( fpo1 );

    // decrypt

    fpi0 = fopen( fname_output_file_enc0, "rb" );
    fpi1 = fopen( fname_output_file_enc1, "rb" );
    fpo0 = fopen( fname_output_file_dec, "wb" );

    if ( xrn_join_wrapper( fpi0, fpi1, fpo0, settings ) != 0 ) {
        return 1;
    }

    fclose( fpi0 );
    fclose( fpi1 );
    fclose( fpo0 );

    // compare the two files

    fpi0 = fopen( fname_input_file, "rb" );
    fpo0 = fopen( fname_output_file_dec, "rb" );
    do {
        // Input character from both files
        cnt0 = ( int ) fread( &ch1, sizeof( uint8_t ), 1, fpi0 );
        cnt1 = ( int ) fread( &ch2, sizeof( uint8_t ), 1, fpo0 );
        error = ( ( ch1 != ch2 ) || ( cnt0 != cnt1 ) ) || error;

    } while ( cnt0 != 0 && cnt1 != 0 );

    fclose( fpi0 );
    fclose( fpo0 );

    remove( fname_input_file );
    remove( fname_output_file_enc0 );
    remove( fname_output_file_enc1 );
    remove( fname_output_file_dec );

    if ( error != 0 ) {
        return 1;
    }

    return 0;

}

int test_encrypt_symmetric_crc(
 )
{

    int error, read_bytes, crc_bytes;

    FILE *fpi;                  // input file
    FILE *fpo;                  // output file
    FILE *fpk;                  // key
    FILE *fpm;                  // matrix
    FILE *fpc;                  // corrupted

    int base_max_value, offset_value, i;
    uint8_t ch;
    char fname_input_file[256];
    char fname_xgenesis_file[256];
    char fname_xrn_matrix[256];
    char fname_key[256];
    char fname_output_file_enc[256];
    char fname_output_file_dec[256];
    char fname_corrupted[256];
    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );
    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    base_max_value = 5;
    offset_value = 0;

    strcpy( fname_input_file, "../cache/to_remove_load_symmetric_all_file.txt" );
    strcpy( fname_xgenesis_file, "../cache/to_remove_load_symmetric_all_ob.txt" );
    strcpy( fname_key, "../cache/to_remove_load_symmetric_all_key.txt" );
    strcpy( fname_xrn_matrix, "../cache/to_remove_load_symmetric_all_xm.txt" );
    strcpy( fname_output_file_enc, "../cache/to_remove_load_symmetric_output_enc.txt" );
    strcpy( fname_output_file_dec, "../cache/to_remove_load_symmetric_output_dec.txt" );
    strcpy( fname_corrupted, "../cache/to_remove_load_symmetric_corrupted.txt" );

    generate_file_matrix_key_monomial( 1, base_max_value, offset_value,
                                       fname_input_file, fname_xgenesis_file, fname_xrn_matrix, fname_key,
                                       settings );

    // encrypt

    fpi = fopen( fname_input_file, "rb" );
    fpm = fopen( fname_xrn_matrix, "rb" );
    fpk = fopen( fname_key, "rb" );
    fpo = fopen( fname_output_file_enc, "wb" );

    error = 0;

    if ( xrn_encrypt_symmetric_wrapper( fpi, fpm, fpk, fpo, settings ) != 0 ) {
        error = 1;
    }

    fclose( fpi );
    fclose( fpm );
    fclose( fpk );
    fclose( fpo );

    // corrupt

    fpi = fopen( fname_output_file_enc, "rb" );
    fpc = fopen( fname_corrupted, "wb" );

    i = 0;

    read_bytes = ( int ) fread( &ch, sizeof( uint8_t ), 1, fpi );
    while ( read_bytes == 1 ) {
        // copy 
        if ( i != 10 ) {
            fwrite( &ch, 1, sizeof( uint8_t ), fpc );

            // corrupt 
        } else {
            ch = ( uint8_t ) ( ~ch );
            fwrite( &ch, 1, sizeof( uint8_t ), fpc );
        }

        i++;
        read_bytes = ( int ) fread( &ch, sizeof( uint8_t ), 1, fpi );
    }

    fclose( fpi );
    fclose( fpc );

    // decrypt

    fpc = fopen( fname_corrupted, "rb" );
    fpm = fopen( fname_xrn_matrix, "rb" );
    fpk = fopen( fname_key, "rb" );
    fpo = fopen( fname_output_file_dec, "wb" );

    if ( xrn_decrypt_symmetric_wrapper( fpc, fpm, fpk, fpo, settings ) == 0 ) {
        error = 1;
    }

    fclose( fpc );
    fclose( fpm );
    fclose( fpk );
    fclose( fpo );

    remove( fname_input_file );
    remove( fname_xgenesis_file );
    remove( fname_xrn_matrix );
    remove( fname_key );
    remove( fname_output_file_enc );
    remove( fname_output_file_dec );
    remove( fname_corrupted );

    if ( error != 0 ) {
        return 1;
    }

    return 0;

}

int test_hash_str_file(
 )
{

    uint8_t str[20000], c;      // arbitrary large string
    char fname[256], fname_xm[256];
    int i, file_size, base_max_value, offset_value, error2, error, crc_bytes;
    uint64_t len;
    FILE *fp;
    xrn_matrix_t *xm;
    xgenesis_base_t *ob;
    xnum_t cob, cos;
    xhash_t hash_str, hash_f;
    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    offset_value = 3;
    base_max_value = 3;

    file_size = ( int )
        ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 -
          2 ) * ( rand(  ) % ( int ) ( base_max_value + offset_value ) ) +
        ( rand(  ) % ( int ) ( ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 ) ) );

    strcpy( fname, "../cache/to_remove_hash_file.txt" );
    fp = fopen( fname, "wb" );

    // create a random string
    // create a random file
    for ( i = 0; ( i < 20000 ) && ( i < file_size ); i++ ) {
        c = ( uint8_t ) rand(  ) % ( 26 + 10 );
        if ( ( c == '\0' ) || ( c == EOF ) ) {
            i--;
        } else {

            str[i] = c;
            fwrite( &c, sizeof( char ), 1, fp );
        }

    }

    str[i] = '\0';
    len = strlen( ( char * ) str );
    fclose( fp );

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );

    // store xrn_matrix 

    strcpy( fname_xm, "../cache/to_remove_hash_xm.txt" );

    // hash the string

    error = xrn_make_hash_bytes( ( uint8_t * ) str, len, xm, &hash_str, settings );

    // hash the file

    fp = fopen( fname, "rb" );

    error = xrn_make_hash( fp, xm, &hash_f, settings ) + error;

    free( xm );

    fclose( fp );

    XNUM_CMP( hash_str.value, hash_f.value, error2 );

    remove( fname_xm );
    remove( fname );

    if ( error + error2 != 0 ) {
        return 1;
    }

    return 0;
}

int test_hash_cmp(
 )
{

    uint8_t str[20000], c;      // arbitrary large string
    char fname[256], fname_xm[256];
    int i, file_size, base_max_value, offset_value, error2, error, error3, error4, error5, crc_bytes;
    uint64_t len;
    FILE *fp;
    xrn_matrix_t *xm;
    xgenesis_base_t *ob;
    xnum_t cob, cos;
    xhash_t hash_str, hash_f;
    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    offset_value = 3;
    base_max_value = 3;

    file_size = ( int )
        ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 -
          2 ) * ( rand(  ) % ( int ) base_max_value + offset_value ) +
        ( rand(  ) % ( int ) ( ( ( sizeof( xnum_t ) * 8 ) * settings.state_size ) / 8 ) );

    strcpy( fname, "../cache/to_remove_hash_file.txt" );
    fp = fopen( fname, "wb" );

    // create a random string
    // create a random file
    for ( i = 0; ( i < 500 ) && ( i < file_size ); i++ ) {
        c = ( uint8_t ) rand(  ) % ( 26 + 10 );
        if ( ( c == '\0' ) || ( c == EOF ) ) {
            i--;
        } else {

            str[i] = c;
            fwrite( &c, sizeof( char ), 1, fp );
        }

    }

    str[i] = '\0';
    len = strlen( ( char * ) str );
    fclose( fp );

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );

    // store xrn_matrix 

    strcpy( fname_xm, "../cache/to_remove_hash_xm.txt" );

    // hash the file

    fp = fopen( fname, "rb" );

    error = xrn_make_hash( fp, xm, &hash_f, settings );

    fclose( fp );

    // hash the string

    error = xrn_make_hash_bytes( ( uint8_t * ) str, len, xm, &hash_str, settings ) + error;

    XNUM_CMP( hash_str.value, hash_f.value, error2 );

    // hash string compare

    if ( xrn_check_hash_bytes( ( uint8_t * ) str, len, hash_str, xm, settings ) == XNOT_EQUAL ) {
        error3 = 1;
    } else {
        error3 = 0;
    }

    // hash negative string compare

    str[( uint64_t ) rand(  ) % len]++;

    if ( xrn_check_hash_bytes( ( uint8_t * ) str, len, hash_str, xm, settings ) == XNOT_EQUAL ) {
        error5 = 0;
    } else {
        error5 = 1;
    }

    // hash file compare

    fp = fopen( fname, "rb" );

    if ( xrn_check_hash( fp, hash_f, xm, settings ) == XNOT_EQUAL ) {
        error4 = 1;
    } else {
        error4 = 0;
    }

    free( xm );
    fclose( fp );

    remove( fname_xm );
    remove( fname );

    if ( error + error2 + error3 + error4 + error5 != 0 ) {
        return 1;
    }

    return 0;
}

int negative_test_signature_sym(
 )
{

    int error, base_max_value, offset_value, crc_bytes;
    FILE *monomial_key_fp, *xrn_matrix_fp, *signature_fp, *input_fp;
    xsignature_sym_t sig;

    char fname[256];
    char fname_xgenesis_file[256];
    char fname_xrn_matrix[256];
    char fname_key[256];
    char fname_signature[256];
    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    base_max_value = 5;
    offset_value = 2;

    strcpy( fname, "../cache/to_remove_input_file" );
    strcpy( fname_signature, "../cache/to_remove_signature" );
    strcpy( fname_xgenesis_file, "../cache/to_remove_load_block_symmetric_all_ob.txt" );
    strcpy( fname_key, "../cache/to_remove_load_block_symmetric_all_key.txt" );
    strcpy( fname_xrn_matrix, "../cache/to_remove_load_block_symmetric_all_xm.txt" );

    generate_file_matrix_key_monomial( 1, base_max_value, offset_value, fname,
                                       fname_xgenesis_file, fname_xrn_matrix, fname_key, settings );

    // generate signature

    signature_fp = fopen( fname_signature, "wb" );
    input_fp = fopen( fname, "rb" );
    monomial_key_fp = fopen( fname_key, "rb" );
    xrn_matrix_fp = fopen( fname_xrn_matrix, "rb" );
    error =
        xrn_make_signature_symmetric_wrapper( input_fp, monomial_key_fp, xrn_matrix_fp, signature_fp,
                                              settings );
    fclose( input_fp );
    fclose( signature_fp );
    fclose( monomial_key_fp );
    fclose( xrn_matrix_fp );

    // corrupt signature

    input_fp = fopen( fname_signature, "rb" );
    xrn_load_signature_sym( &sig, input_fp, &settings );
    fclose( input_fp );
    sig.proof.xnum[0] = sig.proof.xnum[0] + 1;
    input_fp = fopen( fname_signature, "wb" );
    xrn_dump_signature_sym( sig, input_fp, settings );
    fclose( input_fp );

    // check signature

    signature_fp = fopen( fname_signature, "rb" );
    input_fp = fopen( fname, "rb" );
    monomial_key_fp = fopen( fname_key, "rb" );
    xrn_matrix_fp = fopen( fname_xrn_matrix, "rb" );
    error =
        xrn_check_signature_symmetric_wrapper( input_fp, monomial_key_fp, xrn_matrix_fp, signature_fp,
                                               settings ) + error;
    fclose( monomial_key_fp );
    fclose( xrn_matrix_fp );
    fclose( input_fp );
    fclose( signature_fp );

    remove( fname );
    remove( fname_xgenesis_file );
    remove( fname_signature );
    remove( fname_xrn_matrix );
    remove( fname_key );

    if ( error == 0 ) {
        return 1;
    }

    return 0;

}

int test_signature_sym(
 )
{

    int error, base_max_value, offset_value, crc_bytes;
    FILE *monomial_key_fp, *xrn_matrix_fp, *signature_fp, *input_fp;

    char fname[256];
    char fname_xgenesis_file[256];
    char fname_xrn_matrix[256];
    char fname_key[256];
    char fname_signature[256];
    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    base_max_value = 5;
    offset_value = 2;

    strcpy( fname, "../cache/to_remove_input_file" );
    strcpy( fname_signature, "../cache/to_remove_signature" );
    strcpy( fname_xgenesis_file, "../cache/to_remove_load_block_symmetric_all_ob.txt" );
    strcpy( fname_key, "../cache/to_remove_load_block_symmetric_all_key.txt" );
    strcpy( fname_xrn_matrix, "../cache/to_remove_load_block_symmetric_all_xm.txt" );

    generate_file_matrix_key_monomial( 1, base_max_value, offset_value, fname,
                                       fname_xgenesis_file, fname_xrn_matrix, fname_key, settings );

    signature_fp = fopen( fname_signature, "wb" );
    input_fp = fopen( fname, "rb" );
    monomial_key_fp = fopen( fname_key, "rb" );
    xrn_matrix_fp = fopen( fname_xrn_matrix, "rb" );
    error =
        xrn_make_signature_symmetric_wrapper( input_fp, monomial_key_fp, xrn_matrix_fp, signature_fp,
                                              settings );
    fclose( input_fp );
    fclose( signature_fp );
    fclose( monomial_key_fp );
    fclose( xrn_matrix_fp );

    signature_fp = fopen( fname_signature, "rb" );
    input_fp = fopen( fname, "rb" );
    monomial_key_fp = fopen( fname_key, "rb" );
    xrn_matrix_fp = fopen( fname_xrn_matrix, "rb" );
    error =
        xrn_check_signature_symmetric_wrapper( input_fp, monomial_key_fp, xrn_matrix_fp, signature_fp,
                                               settings ) + error;
    fclose( monomial_key_fp );
    fclose( xrn_matrix_fp );
    fclose( input_fp );
    fclose( signature_fp );

    remove( fname );
    remove( fname_xgenesis_file );
    remove( fname_signature );
    remove( fname_xrn_matrix );
    remove( fname_key );

    if ( error != 0 ) {
        return 1;
    }

    return 0;

}

int negative_test_signature_asym(
 )
{

    int error, base_max_value, offset_value, crc_bytes;
    FILE *monomial_key_fp, *binomial_key_fp, *xrn_matrix_fp, *input_fp, *signature_fp;
    xsignature_asy_t sig;

    char fname[256];
    char fname_xgenesis_file[256];
    char fname_xrn_matrix[256];
    char fname_key_binomial[256];
    char fname_key_monomial[256];
    char fname_signature[256];
    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    base_max_value = 5;
    offset_value = 2;

    strcpy( fname, "../cache/to_remove_input_file" );
    strcpy( fname_signature, "../cache/to_remove_signature" );
    strcpy( fname_xgenesis_file, "../cache/to_remove_load_block_symmetric_all_ob.txt" );
    strcpy( fname_key_binomial, "../cache/to_remove_load_block_symmetric_all_key_binomial.txt" );
    strcpy( fname_key_monomial, "../cache/to_remove_load_block_symmetric_all_key_monomial.txt" );
    strcpy( fname_xrn_matrix, "../cache/to_remove_load_block_symmetric_all_xm.txt" );

    generate_file_matrix_key_binomial( 1, base_max_value, offset_value, fname,
                                       fname_xgenesis_file, fname_xrn_matrix, fname_key_binomial,
                                       fname_key_monomial, settings );

    input_fp = fopen( fname, "rb" );
    binomial_key_fp = fopen( fname_key_binomial, "rb" );
    monomial_key_fp = fopen( fname_key_monomial, "rb" );
    xrn_matrix_fp = fopen( fname_xrn_matrix, "rb" );
    signature_fp = fopen( fname_signature, "wb" );
    error =
        xrn_make_signature_asymmetric_wrapper( input_fp, monomial_key_fp, binomial_key_fp, xrn_matrix_fp,
                                               signature_fp, settings );
    fclose( input_fp );
    fclose( binomial_key_fp );
    fclose( monomial_key_fp );
    fclose( xrn_matrix_fp );
    fclose( signature_fp );

    // corrupt signature

    input_fp = fopen( fname_signature, "rb" );
    xrn_load_signature_asy( &sig, input_fp, &settings );
    fclose( input_fp );
    sig.proof.xnum[0] = sig.proof.xnum[0] + 1;
    input_fp = fopen( fname_signature, "wb" );
    xrn_dump_signature_asy( sig, input_fp, settings );
    fclose( input_fp );

    input_fp = fopen( fname, "rb" );
    signature_fp = fopen( fname_signature, "rb" );
    binomial_key_fp = fopen( fname_key_binomial, "rb" );
    xrn_matrix_fp = fopen( fname_xrn_matrix, "rb" );
    error =
        xrn_check_signature_asymmetric_wrapper( input_fp, binomial_key_fp, xrn_matrix_fp, signature_fp,
                                                settings ) + error;
    fclose( input_fp );
    fclose( signature_fp );
    fclose( binomial_key_fp );
    fclose( xrn_matrix_fp );

    remove( fname );
    remove( fname_signature );
    remove( fname_xgenesis_file );
    remove( fname_xrn_matrix );
    remove( fname_key_binomial );
    remove( fname_key_monomial );

    if ( error == 0 ) {
        return 1;
    }

    return 0;

}

int test_signature_asym(
 )
{

    int error, base_max_value, offset_value, crc_bytes;
    FILE *monomial_key_fp, *binomial_key_fp, *xrn_matrix_fp, *input_fp, *signature_fp;

    char fname[256];
    char fname_xgenesis_file[256];
    char fname_xrn_matrix[256];
    char fname_key_binomial[256];
    char fname_key_monomial[256];
    char fname_signature[256];
    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    base_max_value = 5;
    offset_value = 2;

    strcpy( fname, "../cache/to_remove_input_file" );
    strcpy( fname_signature, "../cache/to_remove_signature" );
    strcpy( fname_xgenesis_file, "../cache/to_remove_load_block_symmetric_all_ob.txt" );
    strcpy( fname_key_binomial, "../cache/to_remove_load_block_symmetric_all_key_binomial.txt" );
    strcpy( fname_key_monomial, "../cache/to_remove_load_block_symmetric_all_key_monomial.txt" );
    strcpy( fname_xrn_matrix, "../cache/to_remove_load_block_symmetric_all_xm.txt" );

    generate_file_matrix_key_binomial( 1, base_max_value, offset_value, fname,
                                       fname_xgenesis_file, fname_xrn_matrix, fname_key_binomial,
                                       fname_key_monomial, settings );

    input_fp = fopen( fname, "rb" );
    binomial_key_fp = fopen( fname_key_binomial, "rb" );
    monomial_key_fp = fopen( fname_key_monomial, "rb" );
    xrn_matrix_fp = fopen( fname_xrn_matrix, "rb" );
    signature_fp = fopen( fname_signature, "wb" );
    error =
        xrn_make_signature_asymmetric_wrapper( input_fp, monomial_key_fp, binomial_key_fp, xrn_matrix_fp,
                                               signature_fp, settings );
    fclose( input_fp );
    fclose( binomial_key_fp );
    fclose( monomial_key_fp );
    fclose( xrn_matrix_fp );
    fclose( signature_fp );

    input_fp = fopen( fname, "rb" );
    signature_fp = fopen( fname_signature, "rb" );
    binomial_key_fp = fopen( fname_key_binomial, "rb" );
    xrn_matrix_fp = fopen( fname_xrn_matrix, "rb" );
    error =
        xrn_check_signature_asymmetric_wrapper( input_fp, binomial_key_fp, xrn_matrix_fp, signature_fp,
                                                settings ) + error;
    fclose( input_fp );
    fclose( signature_fp );
    fclose( binomial_key_fp );
    fclose( xrn_matrix_fp );

    remove( fname );
    remove( fname_signature );
    remove( fname_xgenesis_file );
    remove( fname_xrn_matrix );
    remove( fname_key_binomial );
    remove( fname_key_monomial );

    if ( error != 0 ) {
        return 1;
    }

    return 0;

}

int test_key_exchange_wrapper(
 )
{

    int error, crc_bytes;
    xgenesis_base_t *ob;
    xrn_matrix_t *xm;
    xnum_t cob, cos;

    FILE *start_point_fp, *monomial_key_Alice_fp, *fpm, *shared_key_Alice_fp, *shared_key_Bob_fp;
    FILE *monomial_key_Bob_fp, *binomial_key_Bob_fp, *binomial_key_Alice_fp;

    char start_point_str[256];

    xstart_point_t start;

    char binomial_key_str_Alice[256];
    char monomial_key_str_Alice[256];
    char shared_key_str_Alice[256];

    char binomial_key_str_Bob[256];
    char monomial_key_str_Bob[256];
    char shared_key_str_Bob[256];

    char fname_xm[256];

    xbinomial_key_t binomial_key_Alice;
    xmonomial_key_t monomial_key_Alice;
    xmonomial_key_t shared_key_Alice;

    xbinomial_key_t binomial_key_Bob;
    xmonomial_key_t monomial_key_Bob;
    xmonomial_key_t shared_key_Bob;

    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    error = 0;

    strcpy( fname_xm, "../cache/to_remove_xm.txt" );
    strcpy( start_point_str, "../cache/to_remove_start_point.txt" );

    strcpy( monomial_key_str_Alice, "../cache/to_remove_monomial_key_Alice.txt" );
    strcpy( binomial_key_str_Alice, "../cache/to_remove_binomial_key_Alice.txt" );
    strcpy( shared_key_str_Alice, "../cache/to_remove_shared_key_Alice.txt" );

    strcpy( monomial_key_str_Bob, "../cache/to_remove_monomial_key_Bob.txt" );
    strcpy( binomial_key_str_Bob, "../cache/to_remove_binomial_key_Bob.txt" );
    strcpy( shared_key_str_Bob, "../cache/to_remove_shared_key_Bob.txt" );

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );

    // store xrn_matrix 

    fpm = fopen( fname_xm, "wb" );
    xrn_dump_matrix( xm, fpm, settings );
    fclose( fpm );

    // generate origin

    start_point_fp = fopen( start_point_str, "wb" );
    xrn_make_start_point( &start, xm, settings );
    xrn_dump_start_point( start, start_point_fp, settings );
    fclose( start_point_fp );

    // Alice monomial binomial keys
    xrn_make_monomial_key( &monomial_key_Alice, settings );

    binomial_key_Alice_fp = fopen( binomial_key_str_Alice, "wb" );
    monomial_key_Alice_fp = fopen( monomial_key_str_Alice, "wb" );
    error = xrn_make_binomial_key( xm, start, monomial_key_Alice, &binomial_key_Alice, settings ) + error;
    xrn_dump_binomial_key( binomial_key_Alice, binomial_key_Alice_fp, settings );
    xrn_dump_monomial_key( monomial_key_Alice, monomial_key_Alice_fp, settings );
    fclose( binomial_key_Alice_fp );
    fclose( monomial_key_Alice_fp );

    // Bob monomial key
    xrn_make_monomial_key( &monomial_key_Bob, settings );

    binomial_key_Bob_fp = fopen( binomial_key_str_Bob, "wb" );
    monomial_key_Bob_fp = fopen( monomial_key_str_Bob, "wb" );
    error = xrn_make_binomial_key( xm, start, monomial_key_Bob, &binomial_key_Bob, settings ) + error;
    xrn_dump_binomial_key( binomial_key_Bob, binomial_key_Bob_fp, settings );
    xrn_dump_monomial_key( monomial_key_Bob, monomial_key_Bob_fp, settings );
    fclose( binomial_key_Bob_fp );
    fclose( monomial_key_Bob_fp );

    free( xm );

    // Key exchange Alice

    fpm = fopen( fname_xm, "rb" );
    binomial_key_Alice_fp = fopen( binomial_key_str_Alice, "rb" );
    monomial_key_Alice_fp = fopen( monomial_key_str_Alice, "rb" );
    binomial_key_Bob_fp = fopen( binomial_key_str_Bob, "rb" );
    shared_key_Alice_fp = fopen( shared_key_str_Alice, "wb" );

    error = xrn_exchange_monomial_key_wrapper( fpm,
                                               binomial_key_Alice_fp,
                                               binomial_key_Bob_fp, monomial_key_Alice_fp,
                                               shared_key_Alice_fp, settings ) + error;

    fclose( fpm );
    fclose( binomial_key_Alice_fp );
    fclose( monomial_key_Alice_fp );
    fclose( binomial_key_Bob_fp );
    fclose( shared_key_Alice_fp );

    // Key exchange Bob

    binomial_key_Bob_fp = fopen( binomial_key_str_Bob, "rb" );
    monomial_key_Bob_fp = fopen( monomial_key_str_Bob, "rb" );
    binomial_key_Alice_fp = fopen( binomial_key_str_Alice, "rb" );
    shared_key_Bob_fp = fopen( shared_key_str_Bob, "wb" );
    fpm = fopen( fname_xm, "rb" );

    error = xrn_exchange_monomial_key_wrapper( fpm,
                                               binomial_key_Bob_fp,
                                               binomial_key_Alice_fp, monomial_key_Bob_fp,
                                               shared_key_Bob_fp, settings ) + error;

    fclose( fpm );
    fclose( binomial_key_Bob_fp );
    fclose( monomial_key_Bob_fp );
    fclose( binomial_key_Alice_fp );
    fclose( shared_key_Bob_fp );

    // Compare the two shared key

    shared_key_Bob_fp = fopen( shared_key_str_Bob, "rb" );
    shared_key_Alice_fp = fopen( shared_key_str_Alice, "rb" );
    xrn_load_monomial_key( &shared_key_Alice, shared_key_Alice_fp, &settings );
    xrn_load_monomial_key( &shared_key_Bob, shared_key_Bob_fp, &settings );
    fclose( shared_key_Alice_fp );
    fclose( shared_key_Bob_fp );

    if ( error == 0 ) {
        XNUM_CMP( shared_key_Alice.distance, shared_key_Bob.distance, error );
    }

    remove( shared_key_str_Bob );
    remove( shared_key_str_Alice );
    remove( binomial_key_str_Bob );
    remove( binomial_key_str_Alice );
    remove( monomial_key_str_Bob );
    remove( monomial_key_str_Alice );
    remove( start_point_str );
    remove( fname_xm );

    if ( error == 0 ) {
        return 0;
    } else {
        return 1;
    }

    return 0;
}

int test_encrypt_asymmetric_bytes(
 )
{

    int error, crc_bytes;

    uint8_t *in_bytes;
    uint8_t *dec_bytes;
    uint64_t in_length;
    xrn_matrix_t *xm;
    uint8_t *out_bytes;
    uint64_t out_length, out_index;
    uint64_t num_decoded_bytes;
    uint64_t end_block;
    xrn_crypto_extra_settings_t settings;

    uint64_t i;
    xnum_t cob, cos;
    xgenesis_base_t *ob;
    xstart_point_t start;
    xbinomial_key_t binomial_key;
    xmonomial_key_t monomial_key;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    end_block = ( uint64_t ) rand(  ) % 6;
    in_length = sizeof( xnum_t ) * settings.state_size * ( end_block + 1 );

    xrn_estimate_encryption_bytes_length( c_asy_encryption, in_length, &out_length, settings );

    in_bytes = ( uint8_t * ) malloc( in_length * ( sizeof( uint8_t ) ) );
    dec_bytes = ( uint8_t * ) malloc( out_length * ( sizeof( uint8_t ) ) );
    out_bytes = ( uint8_t * ) malloc( out_length * ( sizeof( uint8_t ) ) );

    // initialize input bytes

    for ( i = 0; i < in_length; i++ ) {
        in_bytes[i] = ( uint8_t ) ( rand(  ) % ( ( uint8_t ) ( ( sizeof( xnum_t ) * 8 ) ) + 1 ) );
    }

    // origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );

    xrn_initialize_rnd_num( &start.start );
    xrn_initialize_rnd_num( &monomial_key.distance );
    xrn_make_binomial_key( xm, start, monomial_key, &binomial_key, settings );

    if ( XSUCCESS !=
         xrn_encrypt_asymmetric_bytes( in_bytes, in_length, out_bytes, out_length, &out_index, xm,
                                       binomial_key, settings ) ) {
        free( in_bytes );
        free( dec_bytes );
        free( out_bytes );
        free( xm );
        return 1;
    }

    if ( XSUCCESS != xrn_decrypt_asymmetric_bytes( out_bytes,
                                                   out_length, dec_bytes, out_length, &num_decoded_bytes, xm,
                                                   monomial_key, settings ) ) {
        free( in_bytes );
        free( dec_bytes );
        free( out_bytes );
        free( xm );
        return 1;
    }

    free( xm );

    for ( i = 0; i < in_length; i++ ) {
        error = in_bytes[i] != dec_bytes[i];
        if ( error ) {
            free( in_bytes );
            free( dec_bytes );
            free( out_bytes );
            return 1;
        }

    }

    free( in_bytes );
    free( dec_bytes );
    free( out_bytes );

    if ( in_length != num_decoded_bytes ) {
        return 1;
    }

    return 0;

}

int test_encrypt_symmetric_all_file_crc(
 )
{

    int crc_bytes;

    uint8_t *in_bytes;
    uint8_t *dec_bytes;
    uint64_t in_length;
    xrn_matrix_t *xm;
    uint64_t location;
    uint8_t *out_bytes;
    uint64_t out_length, out_index;
    uint64_t num_decoded_bytes;
    uint32_t end_block;
    xrn_crypto_extra_settings_t settings;

    uint64_t i, dec_length;
    xnum_t cob, cos;
    xgenesis_base_t *ob;
    xstart_point_t start;
    xmonomial_key_t monomial_key;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    end_block = ( uint32_t ) rand(  ) % 6;

    in_length = sizeof( xnum_t ) * ( uint64_t ) ( settings.state_size + 1 ) * ( end_block + 1 );

    xrn_estimate_encryption_bytes_length( c_sym_encryption, in_length, &out_length, settings );

    in_bytes = ( uint8_t * ) malloc( in_length * ( sizeof( uint8_t ) ) );
    out_bytes = ( uint8_t * ) malloc( out_length * ( sizeof( uint8_t ) ) );

    // initialize input bytes

    for ( i = 0; i < in_length; i++ ) {
        in_bytes[i] = ( uint8_t ) ( rand(  ) % ( ( uint8_t ) ( sizeof( xnum_t ) * 8 ) + 1 ) );
    }

    // origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );

    xrn_initialize_rnd_num( &start.start );
    xrn_initialize_rnd_num( &monomial_key.distance );

    if ( XSUCCESS !=
         xrn_encrypt_symmetric_bytes( in_bytes, in_length, out_bytes, out_length, &out_index, xm,
                                      monomial_key, settings ) ) {
        free( in_bytes );
        free( out_bytes );
        return 1;
    }

    xrn_estimate_decryption_bytes_length( c_sym_encryption, out_length, &dec_length, settings );

    dec_bytes = ( uint8_t * ) malloc( dec_length * ( sizeof( uint8_t ) ) );

    // add permutation
    location = ( uint64_t ) rand(  ) % ( uint64_t ) ( settings.state_size * sizeof( xnum_t ) );
    out_bytes[location] = ( uint8_t ) ( ( int ) out_bytes[location] + 1 );

    if ( XSUCCESS != xrn_decrypt_symmetric_bytes( out_bytes,
                                                  out_length, dec_bytes, dec_length, &num_decoded_bytes, xm,
                                                  monomial_key, settings ) ) {
        free( in_bytes );
        free( out_bytes );
        free( dec_bytes );
        free( xm );
        return 0;
    }

    free( in_bytes );
    free( out_bytes );
    free( dec_bytes );
    free( xm );
    return 1;

}

int test_encrypt_symmetric_bytes(
 )
{

    int error, crc_bytes;

    uint8_t *in_bytes;
    uint8_t *dec_bytes;
    uint64_t in_length;
    xrn_matrix_t *xm;
    uint8_t *out_bytes;
    uint64_t out_length, out_index;
    uint64_t num_decoded_bytes;
    uint32_t end_block;
    xrn_crypto_extra_settings_t settings;

    uint64_t i, dec_length;
    xnum_t cob, cos;
    xgenesis_base_t *ob;
    xstart_point_t start;
    xmonomial_key_t monomial_key;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    end_block = ( uint32_t ) rand(  ) % 6;

    in_length = sizeof( xnum_t ) * settings.state_size * ( end_block + 1 );

    xrn_estimate_encryption_bytes_length( c_sym_encryption, in_length, &out_length, settings );

    in_bytes = ( uint8_t * ) malloc( in_length * ( sizeof( uint8_t ) ) );
    out_bytes = ( uint8_t * ) malloc( out_length * ( sizeof( uint8_t ) ) );

    // initialize input bytes

    for ( i = 0; i < in_length; i++ ) {
        in_bytes[i] = ( uint8_t ) ( rand(  ) % ( ( uint8_t ) ( sizeof( xnum_t ) * 8 ) + 1 ) );
    }

    // origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );

    xrn_initialize_rnd_num( &start.start );
    xrn_initialize_rnd_num( &monomial_key.distance );

    if ( XSUCCESS !=
         xrn_encrypt_symmetric_bytes( in_bytes, in_length, out_bytes, out_length, &out_index, xm,
                                      monomial_key, settings ) ) {
        return 1;
    }

    xrn_estimate_decryption_bytes_length( c_sym_encryption, out_length, &dec_length, settings );

    dec_bytes = ( uint8_t * ) malloc( dec_length * ( sizeof( uint8_t ) ) );

    if ( XSUCCESS != xrn_decrypt_symmetric_bytes( out_bytes,
                                                  out_length, dec_bytes, dec_length, &num_decoded_bytes, xm,
                                                  monomial_key, settings ) ) {
        return 1;
    }

    free( xm );

    for ( i = 0; i < in_length; i++ ) {
        error = in_bytes[i] != dec_bytes[i];
        if ( error ) {
            return 1;
        }

    }

    free( dec_bytes );
    free( in_bytes );
    free( out_bytes );

    if ( in_length != num_decoded_bytes ) {
        return 1;
    }

    return 0;

}

int test_loop_enc_stream(
 )
{

    int error, crc_bytes, ret, final_ret;

    uint8_t *in_bytes;
    uint64_t in_length;
    xrn_matrix_t *xm;
    uint8_t *out_bytes, *out_bytes_2;
    uint64_t out_length, num_encoded_bytes;
    uint64_t end_block;
    xrn_crypto_extra_settings_t settings;
    xrn_encoding_param_t enc_param;

    uint64_t i;
    xnum_t cob, cos;
    xnum_t init_vector;

    xgenesis_base_t *ob;
    xstart_point_t start;
    xmonomial_key_t monomial_key;
    xstate_t hidden_state;

    char fname_input_file[256];
    char fname_encrypted_file_1[256];

    FILE *input_file_fp, *encrypted_file_1_fp;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    final_ret = XSUCCESS;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    // initialize encoding decoding param

    ret = xrn_initialize_encoding_parameters( &enc_param, settings.encoding_settings.o_settings );
    final_ret = xrn_store_warnings_in_return_value( ret, final_ret );
    if ( final_ret == XERR_GENERAL ) {
        printf( XERR_GENERAL_MSG );
        return ret;
    }

    strcpy( fname_input_file, "../cache/to_remove_bytes_file_cmp_all_file.txt" );
    strcpy( fname_encrypted_file_1, "../cache/to_remove_bytes_file_cmp_output_enc_1.txt" );

    end_block = ( uint64_t ) rand(  ) % 6;
    in_length = sizeof( xnum_t ) * settings.state_size * ( end_block + 1 );
    out_length = sizeof( xnum_t ) * settings.state_size * ( end_block + 5 );

    in_bytes = ( uint8_t * ) malloc( in_length * ( sizeof( uint8_t ) ) );
    out_bytes = ( uint8_t * ) malloc( out_length * ( sizeof( uint8_t ) ) );
    out_bytes_2 = ( uint8_t * ) malloc( out_length * ( sizeof( uint8_t ) ) );

    // initialize input bytes

    for ( i = 0; i < in_length; i++ ) {
        in_bytes[i] = ( uint8_t ) ( rand(  ) % ( ( uint8_t ) ( sizeof( xnum_t ) * 8 ) + 1 ) );
    }

    input_file_fp = fopen( fname_input_file, "wb" );
    fwrite( in_bytes, sizeof( uint8_t ) * in_length, 1, input_file_fp );
    fclose( input_file_fp );

    // origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );

    xrn_initialize_rnd_num( &start.start );
    xrn_initialize_rnd_num( &monomial_key.distance );

    xrn_initialize_true_rnd_num( "", &init_vector );

    input_file_fp = fopen( fname_input_file, "rb" );
    encrypted_file_1_fp = fopen( fname_encrypted_file_1, "wb" );

    hidden_state.xnums = ( xnum_t * ) malloc( sizeof( xnum_t ) * ( uint64_t ) ( settings.state_size + 1 ) );
    expand_xnum( xm, monomial_key.distance, &hidden_state, settings );

    if ( XSUCCESS !=
         loop_enc_stream( input_file_fp, encrypted_file_1_fp, &hidden_state, xm, init_vector, enc_param,
                          settings ) ) {
        free( in_bytes );
        free( out_bytes );
        free( out_bytes_2 );
        fclose( input_file_fp );
        fclose( encrypted_file_1_fp );
        free( hidden_state.xnums );
        free( xm );
        remove( fname_encrypted_file_1 );
        remove( fname_input_file );
        return 1;
    }

    fclose( input_file_fp );
    fclose( encrypted_file_1_fp );

    if ( XSUCCESS != loop_enc_bytes( in_bytes,
                                     in_length,
                                     out_bytes, out_length, 0, &num_encoded_bytes, &hidden_state, xm,
                                     init_vector, enc_param, settings ) ) {
        free( in_bytes );
        free( out_bytes );
        free( out_bytes_2 );
        free( hidden_state.xnums );
        free( xm );
        remove( fname_encrypted_file_1 );
        remove( fname_input_file );
        return 1;
    }

    free( hidden_state.xnums );
    free( xm );

    encrypted_file_1_fp = fopen( fname_encrypted_file_1, "rb" );
    if ( fread( out_bytes_2, 1, out_length * sizeof( uint8_t ), encrypted_file_1_fp ) != num_encoded_bytes ) {
        fclose( encrypted_file_1_fp );
        remove( fname_encrypted_file_1 );
        remove( fname_input_file );
        free( in_bytes );
        free( out_bytes );
        free( out_bytes_2 );
        return 1;
    }

    fclose( encrypted_file_1_fp );

    remove( fname_encrypted_file_1 );
    remove( fname_input_file );

    error = 0;
    for ( i = 0; i < num_encoded_bytes; i++ ) {
        error = ( out_bytes[i] != out_bytes_2[i] ) || error;
    }

    free( in_bytes );
    free( out_bytes );
    free( out_bytes_2 );

    if ( error != 0 ) {
        return 1;
    }

    return 0;
}

int test_xrn_sign_sym_bytes(
 )
{

    uint8_t *in_bytes;
    uint64_t in_length, crc_bytes;
    xrn_matrix_t *xm;
    uint64_t end_block;
    xrn_crypto_extra_settings_t settings;

    int i;
    xnum_t cob, cos;

    xgenesis_base_t *ob;
    xmonomial_key_t monomial_key;

    char fname_matrix[256];
    char fname_monomial_key[256];
    char fname_signature[256];

    FILE *fpm, *fpk, *fps;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = ( uint64_t ) rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = ( uint64_t ) rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    strcpy( fname_matrix, "../cache/to_remove_sig_sym_bytes_matrix_file.txt" );
    strcpy( fname_monomial_key, "../cache/to_remove_sig_sym_bytes_key_file.txt" );
    strcpy( fname_signature, "../cache/to_remove_sig_sym_bytes_signature_file.txt" );

    end_block = ( uint64_t ) rand(  ) % 4;
    in_length = ( uint64_t ) ( sizeof( xnum_t ) * settings.state_size * ( end_block + 1 ) );

    in_bytes = ( uint8_t * ) malloc( in_length * ( sizeof( uint8_t ) ) );

    // initialize input bytes

    for ( i = 0; i < in_length; i++ ) {
        in_bytes[i] = ( uint8_t ) ( rand(  ) % ( uint8_t ) ( ( sizeof( xnum_t ) * 8 ) + 1 ) );
    }

    // origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    fpm = fopen( fname_matrix, "wb" );
    xrn_dump_matrix( xm, fpm, settings );
    fclose( fpm );

    xrn_initialize_rnd_num( &monomial_key.distance );
    fpk = fopen( fname_monomial_key, "wb" );
    xrn_dump_monomial_key( monomial_key, fpk, settings );
    fclose( fpk );
    free( xm );

    fpm = fopen( fname_matrix, "rb" );
    fpk = fopen( fname_monomial_key, "rb" );
    fps = fopen( fname_signature, "wb" );
    if ( XSUCCESS !=
         xrn_make_signature_symmetric_bytes_wrapper( in_bytes, in_length, fpk, fpm, fps, settings ) ) {

        remove( fname_matrix );
        remove( fname_monomial_key );
        remove( fname_signature );
        free( in_bytes );
        return 1;
    }

    fclose( fpm );
    fclose( fpk );
    fclose( fps );

    fpm = fopen( fname_matrix, "rb" );
    fpk = fopen( fname_monomial_key, "rb" );
    fps = fopen( fname_signature, "rb" );
    if ( XSUCCESS !=
         xrn_check_signature_symmetric_bytes_wrapper( in_bytes, in_length, fpk, fpm, fps, settings ) ) {
        remove( fname_matrix );
        remove( fname_monomial_key );
        remove( fname_signature );
        free( in_bytes );
        return 1;
    }

    fclose( fpm );
    fclose( fpk );
    fclose( fps );

    free( in_bytes );
    remove( fname_matrix );
    remove( fname_monomial_key );
    remove( fname_signature );

    return 0;
}

int negative_test_xrn_sign_sym_bytes(
 )
{

    uint8_t *in_bytes;
    int in_length, crc_bytes;
    xrn_matrix_t *xm;
    uint64_t end_block;
    xrn_crypto_extra_settings_t settings;

    int i;
    xnum_t cob, cos;

    xgenesis_base_t *ob;
    xmonomial_key_t monomial_key;

    char fname_matrix[256];
    char fname_monomial_key[256];
    char fname_signature[256];

    FILE *fpm, *fpk, *fps;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    strcpy( fname_matrix, "../cache/to_remove_sig_sym_bytes_matrix_file.txt" );
    strcpy( fname_monomial_key, "../cache/to_remove_sig_sym_bytes_key_file.txt" );
    strcpy( fname_signature, "../cache/to_remove_sig_sym_bytes_signature_file.txt" );

    end_block = ( uint64_t ) rand(  ) % 6;
    in_length = ( int ) ( sizeof( xnum_t ) * settings.state_size * ( end_block + 1 ) );

    in_bytes = ( uint8_t * ) malloc( ( uint64_t ) in_length * ( uint64_t ) ( sizeof( uint8_t ) ) );

    // initialize input bytes

    for ( i = 0; i < in_length; i++ ) {
        in_bytes[i] = ( uint8_t ) ( rand(  ) % ( ( uint8_t ) ( sizeof( xnum_t ) * 8 ) + 1 ) );
    }

    // origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    fpm = fopen( fname_matrix, "wb" );
    xrn_dump_matrix( xm, fpm, settings );
    fclose( fpm );

    xrn_initialize_rnd_num( &monomial_key.distance );
    fpk = fopen( fname_monomial_key, "wb" );
    xrn_dump_monomial_key( monomial_key, fpk, settings );
    fclose( fpk );

    fpm = fopen( fname_matrix, "rb" );
    fpk = fopen( fname_monomial_key, "rb" );
    fps = fopen( fname_signature, "wb" );
    if ( XSUCCESS !=
         xrn_make_signature_symmetric_bytes_wrapper( in_bytes, ( uint64_t ) in_length, fpk, fpm, fps,
                                                     settings ) ) {

        remove( fname_matrix );
        remove( fname_monomial_key );
        remove( fname_signature );
        free( in_bytes );
        free( xm );
        return 1;
    }

    fclose( fpm );
    fclose( fpk );
    fclose( fps );

    // injecting error
    in_bytes[rand(  ) % in_length]++;

    fpm = fopen( fname_matrix, "rb" );
    fpk = fopen( fname_monomial_key, "rb" );
    fps = fopen( fname_signature, "rb" );
    if ( XSUCCESS !=
         xrn_check_signature_symmetric_bytes_wrapper( in_bytes, ( uint64_t ) in_length, fpk, fpm, fps,
                                                      settings ) ) {
        fclose( fpm );
        fclose( fpk );
        fclose( fps );
        remove( fname_matrix );
        remove( fname_monomial_key );
        remove( fname_signature );
        free( in_bytes );
        free( xm );
        return 0;
    }

    fclose( fpm );
    fclose( fpk );
    fclose( fps );
    free( in_bytes );

    remove( fname_matrix );
    remove( fname_monomial_key );
    remove( fname_signature );

    return 1;

}

int test_xrn_sign_asy_bytes(
 )
{

    uint8_t *in_bytes;
    int in_length, crc_bytes;
    xrn_matrix_t *xm;
    uint64_t end_block;
    xrn_crypto_extra_settings_t settings;
    xstart_point_t start;

    int i;
    xnum_t cob, cos;

    xgenesis_base_t *ob;
    xmonomial_key_t monomial_key;
    xbinomial_key_t binomial_key;

    char fname_matrix[256];
    char fname_monomial_key[256];
    char fname_binomial_key[256];
    char fname_signature[256];

    FILE *fpm, *fpr, *fpu, *fps;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    strcpy( fname_matrix, "../cache/to_remove_sig_sym_bytes_matrix_file.txt" );
    strcpy( fname_monomial_key, "../cache/to_remove_sig_sym_bytes_key_pri_file.txt" );
    strcpy( fname_binomial_key, "../cache/to_remove_sig_sym_bytes_key_binomial_file.txt" );
    strcpy( fname_signature, "../cache/to_remove_sig_sym_bytes_signature_file.txt" );

    end_block = ( uint64_t ) rand(  ) % 6;
    in_length = ( int ) ( sizeof( xnum_t ) * settings.state_size * ( end_block + 1 ) );

    in_bytes = ( uint8_t * ) malloc( ( uint64_t ) in_length * ( uint64_t ) ( sizeof( uint8_t ) ) );

    // initialize input bytes

    for ( i = 0; i < in_length; i++ ) {
        in_bytes[i] = ( uint8_t ) ( rand(  ) % ( ( uint8_t ) ( sizeof( xnum_t ) * 8 ) + 1 ) );
    }

    // origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    fpm = fopen( fname_matrix, "wb" );
    xrn_dump_matrix( xm, fpm, settings );
    fclose( fpm );

    xrn_initialize_rnd_num( &monomial_key.distance );

    fpr = fopen( fname_monomial_key, "wb" );
    xrn_dump_monomial_key( monomial_key, fpr, settings );
    fclose( fpr );

    xrn_initialize_rnd_num( &start.start );
    xrn_make_binomial_key( xm, start, monomial_key, &binomial_key, settings );

    fpu = fopen( fname_binomial_key, "wb" );
    xrn_dump_binomial_key( binomial_key, fpu, settings );
    fclose( fpu );

    fpm = fopen( fname_matrix, "rb" );
    fpr = fopen( fname_monomial_key, "rb" );
    fpu = fopen( fname_binomial_key, "rb" );
    fps = fopen( fname_signature, "wb" );
    if ( XSUCCESS !=
         xrn_make_signature_asymmetric_bytes_wrapper( in_bytes, ( uint64_t ) in_length, fpr, fpu, fpm, fps,
                                                      settings ) ) {

        fclose( fpr );
        fclose( fpm );
        fclose( fpu );
        fclose( fps );
        remove( fname_matrix );
        remove( fname_binomial_key );
        remove( fname_monomial_key );
        remove( fname_signature );
        free( xm );
        free( in_bytes );
        return 1;
    }

    fclose( fpr );
    fclose( fpm );
    fclose( fpu );
    fclose( fps );

    fpm = fopen( fname_matrix, "rb" );
    fpu = fopen( fname_binomial_key, "rb" );
    fps = fopen( fname_signature, "rb" );
    if ( XSUCCESS !=
         xrn_check_signature_asymmetric_bytes_wrapper( in_bytes, ( uint64_t ) in_length, fpu, fpm, fps,
                                                       settings ) ) {
        fclose( fpm );
        fclose( fpu );
        fclose( fps );
        remove( fname_binomial_key );
        remove( fname_matrix );
        remove( fname_monomial_key );
        remove( fname_signature );
        free( in_bytes );
        free( xm );
        return 1;
    }

    fclose( fpm );
    fclose( fpu );
    fclose( fps );

    free( in_bytes );
    free( xm );
    remove( fname_binomial_key );
    remove( fname_matrix );
    remove( fname_monomial_key );
    remove( fname_signature );

    return 0;
}

int negative_test_xrn_sign_asy_bytes(
 )
{

    uint8_t *in_bytes;
    int in_length, crc_bytes;
    xrn_matrix_t *xm;
    uint64_t end_block;
    xrn_crypto_extra_settings_t settings;
    xstart_point_t start;

    int i;
    xnum_t cob, cos;

    xgenesis_base_t *ob;
    xmonomial_key_t monomial_key;
    xbinomial_key_t binomial_key;

    char fname_matrix[256];
    char fname_monomial_key[256];
    char fname_binomial_key[256];
    char fname_signature[256];

    FILE *fpm, *fpr, *fpu, *fps;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    strcpy( fname_matrix, "../cache/to_remove_sig_sym_bytes_matrix_file.txt" );
    strcpy( fname_monomial_key, "../cache/to_remove_sig_sym_bytes_key_pri_file.txt" );
    strcpy( fname_binomial_key, "../cache/to_remove_sig_sym_bytes_key_binomial_file.txt" );
    strcpy( fname_signature, "../cache/to_remove_sig_sym_bytes_signature_file.txt" );

    end_block = ( uint64_t ) rand(  ) % 6;
    in_length =
        ( int ) ( ( int ) sizeof( xnum_t ) * ( int ) settings.state_size * ( int ) ( end_block + 1 ) );

    in_bytes = ( uint8_t * ) malloc( ( uint64_t ) in_length * ( uint64_t ) ( sizeof( uint8_t ) ) );

    // initialize input bytes

    for ( i = 0; i < in_length; i++ ) {
        in_bytes[i] = ( uint8_t ) ( rand(  ) % ( ( uint8_t ) ( sizeof( xnum_t ) * 8 ) + 1 ) );
    }

    // origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    fpm = fopen( fname_matrix, "wb" );
    xrn_dump_matrix( xm, fpm, settings );
    fclose( fpm );

    xrn_initialize_rnd_num( &monomial_key.distance );

    fpr = fopen( fname_monomial_key, "wb" );
    xrn_dump_monomial_key( monomial_key, fpr, settings );
    fclose( fpr );

    xrn_initialize_rnd_num( &start.start );
    xrn_make_binomial_key( xm, start, monomial_key, &binomial_key, settings );

    fpu = fopen( fname_binomial_key, "wb" );
    xrn_dump_binomial_key( binomial_key, fpu, settings );
    fclose( fpu );

    fpm = fopen( fname_matrix, "rb" );
    fpr = fopen( fname_monomial_key, "rb" );
    fpu = fopen( fname_binomial_key, "rb" );
    fps = fopen( fname_signature, "wb" );
    if ( XSUCCESS !=
         xrn_make_signature_asymmetric_bytes_wrapper( in_bytes, ( uint64_t ) in_length, fpr, fpu, fpm, fps,
                                                      settings ) ) {

        fclose( fpm );
        fclose( fpu );
        fclose( fpr );
        fclose( fps );
        remove( fname_matrix );
        remove( fname_binomial_key );
        remove( fname_monomial_key );
        remove( fname_signature );
        free( xm );
        return 1;
    }

    fclose( fpm );
    fclose( fpu );
    fclose( fpr );
    fclose( fps );

    // injecting error
    in_bytes[rand(  ) % in_length]++;

    fpm = fopen( fname_matrix, "rb" );
    fpu = fopen( fname_binomial_key, "rb" );
    fps = fopen( fname_signature, "rb" );
    if ( XSUCCESS !=
         xrn_check_signature_asymmetric_bytes_wrapper( in_bytes, ( uint64_t ) in_length, fpu, fpm, fps,
                                                       settings ) ) {
        fclose( fpm );
        fclose( fpu );
        fclose( fps );
        remove( fname_binomial_key );
        remove( fname_matrix );
        remove( fname_monomial_key );
        remove( fname_signature );
        free( xm );
        free( in_bytes );
        return 0;
    }

    free( in_bytes );
    fclose( fpm );
    fclose( fpu );
    fclose( fps );

    free( xm );
    remove( fname_binomial_key );
    remove( fname_matrix );
    remove( fname_monomial_key );
    remove( fname_signature );

    return 1;
}

int xrn_ring_sig_test_bytes(
 )
{

    //   int error , cnt0 , cnt1;
    xgenesis_base_t *ob;
    xrn_matrix_t *xm;
    xnum_t cob, cos;
    int i, ndecoys, crc_bytes;
    xstart_point_t start;
    xbinomial_key_t binomial_A, binomial_x, binomial_B, *ring;
    xmonomial_key_t monomial_A, monomial_B;
    xring_signature_t xring;

    uint8_t *in_bytes;
    int in_length;

    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );

    // generate bob monomial and binomial key

    xrn_make_start_point( &start, xm, settings );

    xrn_make_monomial_key( &monomial_A, settings );
    xrn_make_monomial_key( &monomial_B, settings );
    xrn_make_binomial_key( xm, start, monomial_A, &binomial_A, settings );
    xrn_make_binomial_key( xm, start, monomial_B, &binomial_B, settings );

    // generate binomial keys
    ndecoys = 5;

    ring = ( xbinomial_key_t * ) malloc( ( uint64_t ) ( ndecoys ) * ( uint64_t ) sizeof( xbinomial_key_t ) );

    in_length =
        ( int ) sizeof( xnum_t ) * ( int ) settings.state_size * ( int ) ( ( uint8_t ) ( rand(  ) ) % 5 );

    while ( in_length <= 0 ) {
        in_length =
            ( int ) sizeof( xnum_t ) * ( int ) settings.state_size * ( int ) ( ( uint8_t ) ( rand(  ) ) % 5 );
    }

    in_bytes = ( uint8_t * ) malloc( ( uint64_t ) in_length * ( uint64_t ) ( sizeof( uint8_t ) ) );

    // initialize input bytes

    for ( i = 0; i < in_length; i++ ) {
        in_bytes[i] = ( uint8_t ) ( rand(  ) % ( ( uint8_t ) ( sizeof( xnum_t ) * 8 ) + 1 ) );
    }

    // perform ring signature

    for ( i = 0; i < ndecoys; i++ ) {
        xrn_initialize_rnd_num( &ring[i].end );
        ring[i].start = start.start;
    }

    if ( XSUCCESS !=
         xrn_make_ring_signature_bytes( in_bytes, ( uint64_t ) in_length, ring, monomial_A, binomial_A,
                                        binomial_B, xm, ( uint16_t ) ndecoys, &xring, settings ) ) {

        free( ring );
        free( xm );
        free( in_bytes );
        return 1;

    }

    // decrypt the file

    if ( XSUCCESS !=
         xrn_check_ring_signature_bytes( in_bytes, ( uint64_t ) in_length, xring, monomial_B, xm, &binomial_x,
                                         settings ) ) {
        free( in_bytes );
        free( xm );
        free( ring );
        return 1;

    }

    free( xm );
    free( in_bytes );
    free( ring );
    return 0;

}

int test_xrn_make_certificate_symmetric_wrapper(
 )
{

    FILE *issuer_monomial_key_fp;
    FILE *subject_monovalent_key_fp;
    char subject[256];
    FILE *xrn_matrix_fp;
    uint64_t start_validity;
    uint64_t end_validity;
    FILE *certificate_fp;
    xrn_crypto_extra_settings_t settings;
    xmonomial_key_t issuer_monomial_key;
    xmonovalent_key_t subject_monovalent_key;

    xrn_matrix_t *xm;
    xgenesis_base_t *ob;
    xnum_t cob, cos;
    int crc_bytes;

    char issuer_monomial_key_str[256];
    char subject_monovalent_key_str[256];
    char xrn_matrix_str[256];
    char certificate_str[256];

    xpolyvalent_key_t polyvalent_key;
    xpolyvalent_proof_t polyvalent_proof;

    strcpy( issuer_monomial_key_str, "../cache/to_remove_cert_sym_issuer.txt" );
    strcpy( subject_monovalent_key_str, "../cache/to_remove_cert_sym_monovalent_key.txt" );
    strcpy( xrn_matrix_str, "../cache/to_remove_cert_sym_xm.txt" );
    strcpy( certificate_str, "../cache/to_remove_cert_sym_cert.txt" );

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xrn_matrix_fp = fopen( xrn_matrix_str, "wb" );
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, xrn_matrix_fp, settings );
    fclose( xrn_matrix_fp );
    strcpy( subject, "subject" );
    xrn_initialize_rnd_num( &issuer_monomial_key.distance );
    xrn_make_monovalent_key( xm, 0, 0xffffffffffffffff, &polyvalent_key, &polyvalent_proof,
                             &subject_monovalent_key, settings );

    free( xm );
    issuer_monomial_key_fp = fopen( issuer_monomial_key_str, "wb" );
    subject_monovalent_key_fp = fopen( subject_monovalent_key_str, "wb" );
    xrn_dump_monomial_key( issuer_monomial_key, issuer_monomial_key_fp, settings );
    xrn_dump_monovalent_key( subject_monovalent_key, subject_monovalent_key_fp, settings );
    fclose( issuer_monomial_key_fp );
    fclose( subject_monovalent_key_fp );

    time( ( time_t * ) & start_validity );
    end_validity = start_validity + 10000;

    issuer_monomial_key_fp = fopen( issuer_monomial_key_str, "rb" );
    subject_monovalent_key_fp = fopen( subject_monovalent_key_str, "rb" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    certificate_fp = fopen( certificate_str, "wb" );

    if ( XSUCCESS != xrn_make_certificate_symmetric_wrapper( issuer_monomial_key_fp,
                                                             subject_monovalent_key_fp,
                                                             subject, xrn_matrix_fp, start_validity,
                                                             end_validity, certificate_fp, settings ) ) {
        remove( issuer_monomial_key_str );
        remove( subject_monovalent_key_str );
        remove( xrn_matrix_str );
        remove( certificate_str );
        return 1;
    }

    fclose( issuer_monomial_key_fp );
    fclose( subject_monovalent_key_fp );
    fclose( certificate_fp );
    fclose( xrn_matrix_fp );

    issuer_monomial_key_fp = fopen( issuer_monomial_key_str, "rb" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    certificate_fp = fopen( certificate_str, "rb" );

    if ( XSUCCESS !=
         xrn_check_certificate_symmetric_wrapper( issuer_monomial_key_fp, xrn_matrix_fp, certificate_fp,
                                                  settings ) ) {
        remove( issuer_monomial_key_str );
        remove( subject_monovalent_key_str );
        remove( xrn_matrix_str );
        remove( certificate_str );
        return 1;
    }

    fclose( issuer_monomial_key_fp );
    fclose( certificate_fp );
    fclose( xrn_matrix_fp );

    remove( issuer_monomial_key_str );
    remove( subject_monovalent_key_str );
    remove( xrn_matrix_str );
    remove( certificate_str );

    return 0;
}

int negative_test_xrn_make_certificate_asymmetric_wrapper_time(
 )
{

    FILE *issuer_binomial_key_fp;
    FILE *issuer_monomial_key_fp;
    FILE *subject_binomial_key_fp;
    char subject[256];
    FILE *xrn_matrix_fp;
    uint64_t start_validity;
    uint64_t end_validity;
    FILE *certificate_fp;
    xrn_crypto_extra_settings_t settings;
    xmonomial_key_t issuer_monomial_key;
    xbinomial_key_t issuer_binomial_key;
    xbinomial_key_t subject_binomial_key;
    uint8_t constant_execution, force_linearity, check_sparcity;

    xrn_matrix_t *xm;
    xgenesis_base_t *ob;
    xnum_t cob, cos;
    int crc_bytes;

    char issuer_monomial_key_str[256];
    char issuer_binomial_key_str[256];
    char subject_binomial_key_str[256];
    char xrn_matrix_str[256];
    char certificate_str[256];

    strcpy( issuer_monomial_key_str, "../cache/to_remove_cert_sym_issuer_monomial.txt" );
    strcpy( issuer_binomial_key_str, "../cache/to_remove_cert_sym_issuer_binomial.txt" );
    strcpy( subject_binomial_key_str, "../cache/to_remove_cert_sym_binomial_key.txt" );
    strcpy( xrn_matrix_str, "../cache/to_remove_cert_sym_xm.txt" );
    strcpy( certificate_str, "../cache/to_remove_cert_sym_cert.txt" );

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xrn_matrix_fp = fopen( xrn_matrix_str, "wb" );
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, xrn_matrix_fp, settings );
    fclose( xrn_matrix_fp );

    strcpy( subject, "subject" );
    xrn_initialize_rnd_num( &issuer_monomial_key.distance );
    xrn_initialize_rnd_num( &subject_binomial_key.end );
    xrn_initialize_rnd_num( &subject_binomial_key.start );
    xrn_initialize_rnd_num( &issuer_binomial_key.start );

    constant_execution = 0;
    force_linearity = 0;
    check_sparcity = 1;

    xrn_permute_matrix( xm );

    xrn_matrix_traverse( xm, &issuer_binomial_key.start, &issuer_monomial_key.distance,
                         &issuer_binomial_key.end, &constant_execution, &force_linearity, &check_sparcity );
    free( xm );

    issuer_monomial_key_fp = fopen( issuer_monomial_key_str, "wb" );
    issuer_binomial_key_fp = fopen( issuer_binomial_key_str, "wb" );
    subject_binomial_key_fp = fopen( subject_binomial_key_str, "wb" );
    xrn_dump_monomial_key( issuer_monomial_key, issuer_monomial_key_fp, settings );
    xrn_dump_binomial_key( issuer_binomial_key, issuer_binomial_key_fp, settings );
    xrn_dump_binomial_key( subject_binomial_key, subject_binomial_key_fp, settings );
    fclose( issuer_monomial_key_fp );
    fclose( subject_binomial_key_fp );
    fclose( issuer_binomial_key_fp );

    start_validity = 0;
    end_validity = start_validity + 1000;

    issuer_binomial_key_fp = fopen( issuer_binomial_key_str, "rb" );
    issuer_monomial_key_fp = fopen( issuer_monomial_key_str, "rb" );
    subject_binomial_key_fp = fopen( subject_binomial_key_str, "rb" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    certificate_fp = fopen( certificate_str, "wb" );

    if ( XSUCCESS != xrn_make_certificate_asymmetric_wrapper( issuer_monomial_key_fp,
                                                              issuer_binomial_key_fp,
                                                              subject_binomial_key_fp,
                                                              subject, xrn_matrix_fp, start_validity,
                                                              end_validity, certificate_fp, settings ) ) {
        fclose( issuer_monomial_key_fp );
        fclose( issuer_binomial_key_fp );
        fclose( subject_binomial_key_fp );
        fclose( certificate_fp );
        fclose( xrn_matrix_fp );
        remove( issuer_monomial_key_str );
        remove( subject_binomial_key_str );
        remove( xrn_matrix_str );
        remove( certificate_str );
        return 1;
    }

    fclose( issuer_monomial_key_fp );
    fclose( issuer_binomial_key_fp );
    fclose( subject_binomial_key_fp );
    fclose( certificate_fp );
    fclose( xrn_matrix_fp );

    issuer_binomial_key_fp = fopen( issuer_binomial_key_str, "rb" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    certificate_fp = fopen( certificate_str, "rb" );

    if ( XSUCCESS !=
         xrn_check_certificate_asymmetric_wrapper( issuer_binomial_key_fp, xrn_matrix_fp, certificate_fp,
                                                   settings ) ) {
        fclose( issuer_binomial_key_fp );
        fclose( certificate_fp );
        fclose( xrn_matrix_fp );
        remove( issuer_monomial_key_str );
        remove( subject_binomial_key_str );
        remove( xrn_matrix_str );
        remove( certificate_str );
        return 0;
    }

    fclose( issuer_binomial_key_fp );
    fclose( certificate_fp );
    fclose( xrn_matrix_fp );

    remove( issuer_monomial_key_str );
    remove( subject_binomial_key_str );
    remove( xrn_matrix_str );
    remove( certificate_str );

    return 1;
}

int test_xrn_make_certificate_asymmetric_wrapper(
 )
{

    FILE *issuer_binomial_key_fp;
    FILE *issuer_monomial_key_fp;
    FILE *subject_binomial_key_fp;
    char subject[256];
    FILE *xrn_matrix_fp;
    uint64_t start_validity;
    uint64_t end_validity;
    FILE *certificate_fp;
    xrn_crypto_extra_settings_t settings;
    xmonomial_key_t issuer_monomial_key;
    xbinomial_key_t issuer_binomial_key;
    xbinomial_key_t subject_binomial_key;
    uint8_t constant_execution, force_linearity, check_sparcity;

    xrn_matrix_t *xm;
    xgenesis_base_t *ob;
    xnum_t cob, cos;
    int crc_bytes;

    char issuer_monomial_key_str[256];
    char issuer_binomial_key_str[256];
    char subject_binomial_key_str[256];
    char xrn_matrix_str[256];
    char certificate_str[256];

    strcpy( issuer_monomial_key_str, "../cache/to_remove_cert_sym_issuer_monomial.txt" );
    strcpy( issuer_binomial_key_str, "../cache/to_remove_cert_sym_issuer_binomial.txt" );
    strcpy( subject_binomial_key_str, "../cache/to_remove_cert_sym_binomial_key.txt" );
    strcpy( xrn_matrix_str, "../cache/to_remove_cert_sym_xm.txt" );
    strcpy( certificate_str, "../cache/to_remove_cert_sym_cert.txt" );

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xrn_matrix_fp = fopen( xrn_matrix_str, "wb" );
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, xrn_matrix_fp, settings );
    fclose( xrn_matrix_fp );

    strcpy( subject, "subject" );
    xrn_initialize_rnd_num( &issuer_monomial_key.distance );
    xrn_initialize_rnd_num( &subject_binomial_key.end );
    xrn_initialize_rnd_num( &subject_binomial_key.start );
    xrn_initialize_rnd_num( &issuer_binomial_key.start );

    constant_execution = 0;
    force_linearity = 0;
    check_sparcity = 1;

    xrn_permute_matrix( xm );

    xrn_matrix_traverse( xm, &issuer_binomial_key.start, &issuer_monomial_key.distance,
                         &issuer_binomial_key.end, &constant_execution, &force_linearity, &check_sparcity );
    free( xm );

    issuer_monomial_key_fp = fopen( issuer_monomial_key_str, "wb" );
    issuer_binomial_key_fp = fopen( issuer_binomial_key_str, "wb" );
    subject_binomial_key_fp = fopen( subject_binomial_key_str, "wb" );
    xrn_dump_monomial_key( issuer_monomial_key, issuer_monomial_key_fp, settings );
    xrn_dump_binomial_key( issuer_binomial_key, issuer_binomial_key_fp, settings );
    xrn_dump_binomial_key( subject_binomial_key, subject_binomial_key_fp, settings );
    fclose( issuer_monomial_key_fp );
    fclose( subject_binomial_key_fp );
    fclose( issuer_binomial_key_fp );

    time( ( time_t * ) & start_validity );
    end_validity = start_validity + 10000;

    issuer_binomial_key_fp = fopen( issuer_binomial_key_str, "rb" );
    issuer_monomial_key_fp = fopen( issuer_monomial_key_str, "rb" );
    subject_binomial_key_fp = fopen( subject_binomial_key_str, "rb" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    certificate_fp = fopen( certificate_str, "wb" );

    if ( XSUCCESS != xrn_make_certificate_asymmetric_wrapper( issuer_monomial_key_fp,
                                                              issuer_binomial_key_fp,
                                                              subject_binomial_key_fp,
                                                              subject, xrn_matrix_fp, start_validity,
                                                              end_validity, certificate_fp, settings ) ) {
        fclose( issuer_monomial_key_fp );
        fclose( issuer_binomial_key_fp );
        fclose( subject_binomial_key_fp );
        fclose( certificate_fp );
        fclose( xrn_matrix_fp );
        remove( issuer_monomial_key_str );
        remove( subject_binomial_key_str );
        remove( xrn_matrix_str );
        remove( certificate_str );
        return 1;
    }

    fclose( issuer_monomial_key_fp );
    fclose( issuer_binomial_key_fp );
    fclose( subject_binomial_key_fp );
    fclose( certificate_fp );
    fclose( xrn_matrix_fp );

    issuer_binomial_key_fp = fopen( issuer_binomial_key_str, "rb" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    certificate_fp = fopen( certificate_str, "rb" );

    if ( XSUCCESS !=
         xrn_check_certificate_asymmetric_wrapper( issuer_binomial_key_fp, xrn_matrix_fp, certificate_fp,
                                                   settings ) ) {
        remove( issuer_monomial_key_str );
        remove( subject_binomial_key_str );
        remove( xrn_matrix_str );
        remove( certificate_str );
        return 1;
    }

    fclose( issuer_binomial_key_fp );
    fclose( certificate_fp );
    fclose( xrn_matrix_fp );

    remove( issuer_monomial_key_str );
    remove( subject_binomial_key_str );
    remove( xrn_matrix_str );
    remove( certificate_str );

    return 0;
}

int negative_test_xrn_make_certificate_symmetric_wrapper_time(
 )
{

    FILE *issuer_monomial_key_fp;
    FILE *subject_monovalent_key_fp;
    char subject[256];
    FILE *xrn_matrix_fp;
    uint64_t start_validity;
    uint64_t end_validity;
    FILE *certificate_fp;
    xrn_crypto_extra_settings_t settings;
    xmonomial_key_t issuer_monomial_key;
    xmonovalent_key_t subject_monovalent_key;

    xrn_matrix_t *xm;
    xgenesis_base_t *ob;
    xnum_t cob, cos;
    int i, crc_bytes;

    xpolyvalent_key_t polyvalent_key;
    xpolyvalent_proof_t polyvalent_proof;

    char issuer_monomial_key_str[256];
    char subject_monovalent_key_str[256];
    char xrn_matrix_str[256];
    char certificate_str[256];

    strcpy( issuer_monomial_key_str, "../cache/to_remove_cert_sym_issuer.txt" );
    strcpy( subject_monovalent_key_str, "../cache/to_remove_cert_sym_monovalent_key.txt" );
    strcpy( xrn_matrix_str, "../cache/to_remove_cert_sym_xm.txt" );
    strcpy( certificate_str, "../cache/to_remove_cert_sym_cert.txt" );

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    for ( i = 0; i < sizeof( settings.encoding_settings.i_settings ); i++ ) {
        ( ( uint8_t * ) & settings.encoding_settings.i_settings )[i] = 0;
    }

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xrn_matrix_fp = fopen( xrn_matrix_str, "wb" );
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, xrn_matrix_fp, settings );
    fclose( xrn_matrix_fp );

    strcpy( subject, "subject" );
    xrn_initialize_rnd_num( &issuer_monomial_key.distance );

    xrn_make_monovalent_key( xm, 0, 0xffffffffffffffff, &polyvalent_key, &polyvalent_proof,
                             &subject_monovalent_key, settings );

    issuer_monomial_key_fp = fopen( issuer_monomial_key_str, "wb" );
    subject_monovalent_key_fp = fopen( subject_monovalent_key_str, "wb" );
    xrn_dump_monomial_key( issuer_monomial_key, issuer_monomial_key_fp, settings );
    xrn_dump_monovalent_key( subject_monovalent_key, subject_monovalent_key_fp, settings );
    fclose( issuer_monomial_key_fp );
    fclose( subject_monovalent_key_fp );
    free( xm );
    start_validity = 0;
    end_validity = start_validity + 1000;

    issuer_monomial_key_fp = fopen( issuer_monomial_key_str, "rb" );
    subject_monovalent_key_fp = fopen( subject_monovalent_key_str, "rb" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    certificate_fp = fopen( certificate_str, "wb" );

    if ( XSUCCESS != xrn_make_certificate_symmetric_wrapper( issuer_monomial_key_fp,
                                                             subject_monovalent_key_fp,
                                                             subject, xrn_matrix_fp, start_validity,
                                                             end_validity, certificate_fp, settings ) ) {
        remove( issuer_monomial_key_str );
        remove( subject_monovalent_key_str );
        remove( xrn_matrix_str );
        remove( certificate_str );
        return 1;
    }

    fclose( issuer_monomial_key_fp );
    fclose( subject_monovalent_key_fp );
    fclose( certificate_fp );
    fclose( xrn_matrix_fp );

    issuer_monomial_key_fp = fopen( issuer_monomial_key_str, "rb" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    certificate_fp = fopen( certificate_str, "rb" );

    if ( XSUCCESS !=
         xrn_check_certificate_symmetric_wrapper( issuer_monomial_key_fp, xrn_matrix_fp, certificate_fp,
                                                  settings ) ) {

        fclose( issuer_monomial_key_fp );
        fclose( certificate_fp );
        fclose( xrn_matrix_fp );
        remove( issuer_monomial_key_str );
        remove( subject_monovalent_key_str );
        remove( xrn_matrix_str );
        remove( certificate_str );
        return 0;
    }

    fclose( issuer_monomial_key_fp );
    fclose( certificate_fp );
    fclose( xrn_matrix_fp );

    remove( issuer_monomial_key_str );
    remove( subject_monovalent_key_str );
    remove( xrn_matrix_str );
    remove( certificate_str );

    return 0;
}

int test_xrn_generate_confidential_pseudo_random_number_wrapper(
 )
{

    FILE *monomial_key_fp;
    FILE *xrn_matrix_fp;
    FILE *point1_fp;
    FILE *point2_fp;
    xrn_crypto_extra_settings_t settings;
    xmonomial_key_t monomial_key;
    xrn_point_t point1;
    xrn_point_t point2;

    xrn_matrix_t *xm;
    xgenesis_base_t *ob;
    xnum_t cob, cos;
    int crc_bytes;
    int error;

    char monomial_key_str[256];
    char xrn_matrix_str[256];
    char point1_str[256];
    char point2_str[256];

    strcpy( monomial_key_str, "../cache/to_remove_prng.txt" );
    strcpy( xrn_matrix_str, "../cache/to_remove_prng_xm.txt" );
    strcpy( point1_str, "../cache/to_remove_prng_point1.txt" );
    strcpy( point2_str, "../cache/to_remove_prng_point2.txt" );

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xrn_matrix_fp = fopen( xrn_matrix_str, "wb" );
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, xrn_matrix_fp, settings );
    fclose( xrn_matrix_fp );
    free( xm );

    xrn_initialize_rnd_num( &monomial_key.distance );

    monomial_key_fp = fopen( monomial_key_str, "wb" );
    xrn_dump_monomial_key( monomial_key, monomial_key_fp, settings );
    fclose( monomial_key_fp );

    point1_fp = fopen( point1_str, "wb" );
    xrn_make_point_wrapper( point1_fp, settings );
    fclose( point1_fp );

    monomial_key_fp = fopen( monomial_key_str, "rb" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    point1_fp = fopen( point1_str, "rb" );
    point2_fp = fopen( point2_str, "wb" );

    if ( XSUCCESS !=
         xrn_generate_confidential_pseudo_random_number_wrapper( point1_fp, monomial_key_fp, xrn_matrix_fp,
                                                                 point2_fp, settings ) ) {

        fclose( monomial_key_fp );
        fclose( xrn_matrix_fp );
        fclose( point1_fp );
        fclose( point2_fp );
        remove( point1_str );
        remove( point2_str );
        remove( monomial_key_str );
        remove( xrn_matrix_str );
        return 1;

    }

    fclose( monomial_key_fp );
    fclose( xrn_matrix_fp );
    fclose( point1_fp );
    fclose( point2_fp );

    point1_fp = fopen( point1_str, "rb" );
    point2_fp = fopen( point2_str, "rb" );

    xrn_load_point( &point1, point1_fp, settings );
    xrn_load_point( &point2, point2_fp, settings );

    fclose( point1_fp );
    fclose( point2_fp );

    XNUM_CMP( point1.point, point2.point, error );

    if ( error != 0 ) {
        remove( point1_str );
        remove( point2_str );
        remove( monomial_key_str );
        remove( xrn_matrix_str );
        return 0;
    }

    remove( point1_str );
    remove( point2_str );
    remove( monomial_key_str );
    remove( xrn_matrix_str );
    return 1;

}

int test_verify_binomial_proof(
 )
{

    FILE *binomial_key_fp;
    FILE *monomial_key_fp;
    FILE *xrn_matrix_fp;
    FILE *monomial_commitment_fp;
    FILE *binomial_commitment_fp;
    FILE *monomial_response_fp;
    FILE *monomial_proof_fp;

    char monomial_key_str[256];
    char binomial_key_str[256];
    char xrn_matrix_str[256];
    char monomial_commitment_str[256];
    char binomial_commitment_str[256];
    char monomial_response_str[256];
    char monomial_proof_str[256];

    xrn_crypto_extra_settings_t settings;

    xbinomial_key_t binomial_key;
    xmonomial_key_t monomial_key;
    xstart_point_t start_point;

    xrn_matrix_t *xm;
    xgenesis_base_t *ob;
    xnum_t cob, cos;
    int i;

    strcpy( monomial_key_str, "../cache/to_remove_monomial_key.txt" );
    strcpy( binomial_key_str, "../cache/to_remove_binomial_key.txt" );
    strcpy( xrn_matrix_str, "../cache/to_remove_xrn_matrix.txt" );
    strcpy( monomial_commitment_str, "../cache/to_remove_monomial_commitment.txt" );
    strcpy( binomial_commitment_str, "../cache/to_remove_binomial_commitment.txt" );
    strcpy( monomial_response_str, "../cache/to_remove_monomial_response.txt" );
    strcpy( monomial_proof_str, "../cache/to_remove_monomial_proof.txt" );

    for ( i = 0; i < sizeof( settings.encoding_settings.i_settings ); i++ ) {
        ( ( uint8_t * ) & settings.encoding_settings.i_settings )[i] = 0;
    }

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    xrn_load_default_settings( &settings );

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xrn_matrix_fp = fopen( xrn_matrix_str, "wb" );
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, xrn_matrix_fp, settings );
    fclose( xrn_matrix_fp );

    // load settings

    xrn_initialize_rnd_num( &start_point.start );
    xrn_initialize_rnd_num( &monomial_key.distance );
    xrn_make_binomial_key( xm, start_point, monomial_key, &binomial_key, settings );
    free( xm );

    // make monomial key

    monomial_key_fp = fopen( monomial_key_str, "wb" );
    xrn_dump_monomial_key( monomial_key, monomial_key_fp, settings );
    fclose( monomial_key_fp );

    // make binomial key

    binomial_key_fp = fopen( binomial_key_str, "wb" );
    xrn_dump_binomial_key( binomial_key, binomial_key_fp, settings );
    fclose( binomial_key_fp );

    // make binomial commitment

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    binomial_key_fp = fopen( binomial_key_str, "r" );
    monomial_commitment_fp = fopen( monomial_commitment_str, "w" );
    binomial_commitment_fp = fopen( binomial_commitment_str, "w" );

    if ( XSUCCESS !=
         xrn_make_commitment_from_binomial_key_wrapper( xrn_matrix_fp, binomial_key_fp,
                                                        monomial_commitment_fp, binomial_commitment_fp,
                                                        settings ) ) {
        fclose( xrn_matrix_fp );
        fclose( binomial_key_fp );
        fclose( monomial_commitment_fp );
        fclose( binomial_commitment_fp );

        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;
    }

    fclose( xrn_matrix_fp );
    fclose( binomial_key_fp );
    fclose( monomial_commitment_fp );
    fclose( binomial_commitment_fp );

    // make monomial response

    monomial_response_fp = fopen( monomial_response_str, "w" );

    if ( XSUCCESS != xrn_make_monomial_response_wrapper( monomial_response_fp, settings ) ) {
        fclose( monomial_response_fp );
        return 1;
    }

    fclose( monomial_response_fp );

    // make monomial proof

    binomial_key_fp = fopen( binomial_key_str, "r" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    monomial_key_fp = fopen( monomial_key_str, "r" );
    monomial_commitment_fp = fopen( monomial_commitment_str, "r" );
    monomial_response_fp = fopen( monomial_response_str, "r" );
    monomial_proof_fp = fopen( monomial_proof_str, "w" );

    if ( XSUCCESS !=
         xrn_make_monomial_proof_wrapper( binomial_key_fp, xrn_matrix_fp, monomial_key_fp,
                                          monomial_commitment_fp, monomial_response_fp, monomial_proof_fp,
                                          settings ) ) {

        fclose( binomial_key_fp );
        fclose( xrn_matrix_fp );
        fclose( monomial_key_fp );
        fclose( monomial_commitment_fp );
        fclose( monomial_response_fp );
        fclose( monomial_proof_fp );

        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;

    }

    fclose( binomial_key_fp );
    fclose( xrn_matrix_fp );
    fclose( monomial_key_fp );
    fclose( monomial_commitment_fp );
    fclose( monomial_response_fp );
    fclose( monomial_proof_fp );

    // check monomial proof

    binomial_key_fp = fopen( binomial_key_str, "r" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    monomial_key_fp = fopen( monomial_key_str, "r" );
    binomial_commitment_fp = fopen( binomial_commitment_str, "r" );
    monomial_response_fp = fopen( monomial_response_str, "r" );
    monomial_proof_fp = fopen( monomial_proof_str, "r" );

    if ( XSUCCESS !=
         xrn_check_monomial_proof_wrapper( binomial_key_fp, xrn_matrix_fp, binomial_commitment_fp,
                                           monomial_response_fp, monomial_proof_fp, settings ) ) {

        fclose( binomial_key_fp );
        fclose( xrn_matrix_fp );
        fclose( monomial_key_fp );
        fclose( binomial_commitment_fp );
        fclose( monomial_response_fp );
        fclose( monomial_proof_fp );

        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;

    }

    fclose( binomial_key_fp );
    fclose( xrn_matrix_fp );
    fclose( monomial_key_fp );
    fclose( binomial_commitment_fp );
    fclose( monomial_response_fp );
    fclose( monomial_proof_fp );

    remove( monomial_key_str );
    remove( binomial_key_str );
    remove( xrn_matrix_str );
    remove( monomial_commitment_str );
    remove( binomial_commitment_str );
    remove( monomial_response_str );
    remove( monomial_proof_str );

    return XSUCCESS;

}

int test_verify_signature_bytes_proof(
 )
{

    FILE *binomial_key_fp;
    FILE *monomial_key_fp;
    FILE *xrn_matrix_fp;
    FILE *monomial_commitment_fp;
    FILE *binomial_commitment_fp;
    FILE *monomial_response_fp;
    FILE *monomial_proof_fp;
    FILE *signature_fp;

    char signature_str[256];
    char monomial_key_str[256];
    char binomial_key_str[256];
    char xrn_matrix_str[256];
    char monomial_commitment_str[256];
    char binomial_commitment_str[256];
    char monomial_response_str[256];
    char monomial_proof_str[256];

    xrn_crypto_extra_settings_t settings;

    xbinomial_key_t binomial_key;
    xmonomial_key_t monomial_key;
    xstart_point_t start_point;

    xrn_matrix_t *xm;
    xgenesis_base_t *ob;
    xnum_t cob, cos;

    uint8_t in_bytes[256];
    uint64_t in_length;
    int i;

    strcpy( monomial_key_str, "../cache/to_remove_monomial_key.txt" );
    strcpy( binomial_key_str, "../cache/to_remove_binomial_key.txt" );
    strcpy( signature_str, "../cache/to_remove_signature.txt" );
    strcpy( xrn_matrix_str, "../cache/to_remove_xrn_matrix.txt" );
    strcpy( monomial_commitment_str, "../cache/to_remove_monomial_commitment.txt" );
    strcpy( binomial_commitment_str, "../cache/to_remove_binomial_commitment.txt" );
    strcpy( monomial_response_str, "../cache/to_remove_monomial_response.txt" );
    strcpy( monomial_proof_str, "../cache/to_remove_monomial_proof.txt" );

    for ( i = 0; i < sizeof( settings.encoding_settings.i_settings ); i++ ) {
        ( ( uint8_t * ) & settings.encoding_settings.i_settings )[i] = 0;
    }

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xrn_matrix_fp = fopen( xrn_matrix_str, "wb" );
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, xrn_matrix_fp, settings );
    fclose( xrn_matrix_fp );

    // load settings

    xrn_load_default_settings( &settings );

    xrn_initialize_rnd_num( &start_point.start );
    xrn_initialize_rnd_num( &monomial_key.distance );
    xrn_make_binomial_key( xm, start_point, monomial_key, &binomial_key, settings );
    free( xm );

    // make monomial key

    monomial_key_fp = fopen( monomial_key_str, "wb" );
    xrn_dump_monomial_key( monomial_key, monomial_key_fp, settings );
    fclose( monomial_key_fp );

    // make binomial key

    binomial_key_fp = fopen( binomial_key_str, "wb" );
    xrn_dump_binomial_key( binomial_key, binomial_key_fp, settings );
    fclose( binomial_key_fp );

    // compute a stream of bytes

    in_length = 256;
    for ( i = 0; i < in_length; i++ ) {
        in_bytes[i] = ( uint8_t ) rand(  ) % 256;
    }

    // compute signature

    monomial_key_fp = fopen( monomial_key_str, "r" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    signature_fp = fopen( signature_str, "w" );

    if ( XSUCCESS !=
         xrn_make_signature_symmetric_bytes_wrapper( in_bytes, in_length, monomial_key_fp, xrn_matrix_fp,
                                                     signature_fp, settings ) ) {

        fclose( monomial_key_fp );
        fclose( xrn_matrix_fp );
        fclose( signature_fp );

        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;

    }

    fclose( monomial_key_fp );
    fclose( xrn_matrix_fp );
    fclose( signature_fp );

    // make binomial commitment

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    signature_fp = fopen( signature_str, "r" );
    monomial_commitment_fp = fopen( monomial_commitment_str, "w" );
    binomial_commitment_fp = fopen( binomial_commitment_str, "w" );

    if ( XSUCCESS !=
         xrn_make_commitment_from_sym_signatures_bytes_wrapper( in_bytes, in_length, xrn_matrix_fp,
                                                                signature_fp, monomial_commitment_fp,
                                                                binomial_commitment_fp, settings ) ) {
        fclose( xrn_matrix_fp );
        fclose( signature_fp );
        fclose( monomial_commitment_fp );
        fclose( binomial_commitment_fp );

        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;
    }

    fclose( xrn_matrix_fp );
    fclose( signature_fp );
    fclose( monomial_commitment_fp );
    fclose( binomial_commitment_fp );

    // make monomial response

    monomial_response_fp = fopen( monomial_response_str, "w" );

    if ( XSUCCESS != xrn_make_monomial_response_wrapper( monomial_response_fp, settings ) ) {
        fclose( monomial_response_fp );
        return 1;
    }

    fclose( monomial_response_fp );

    // make monomial proof

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    signature_fp = fopen( signature_str, "r" );
    monomial_key_fp = fopen( monomial_key_str, "r" );
    monomial_commitment_fp = fopen( monomial_commitment_str, "r" );
    monomial_response_fp = fopen( monomial_response_str, "r" );
    monomial_proof_fp = fopen( monomial_proof_str, "w" );

    if ( XSUCCESS !=
         xrn_make_monomial_proof_from_signature_bytes_wrapper( in_bytes, in_length, xrn_matrix_fp,
                                                               signature_fp, monomial_key_fp,
                                                               monomial_commitment_fp,
                                                               monomial_response_fp, monomial_proof_fp,
                                                               settings ) ) {

        fclose( xrn_matrix_fp );
        fclose( signature_fp );
        fclose( monomial_key_fp );
        fclose( monomial_commitment_fp );
        fclose( monomial_response_fp );
        fclose( monomial_proof_fp );

        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;

    }

    fclose( signature_fp );
    fclose( xrn_matrix_fp );
    fclose( monomial_key_fp );
    fclose( monomial_commitment_fp );
    fclose( monomial_response_fp );
    fclose( monomial_proof_fp );

    // check monomial proof

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    monomial_key_fp = fopen( monomial_key_str, "r" );
    signature_fp = fopen( signature_str, "r" );
    binomial_commitment_fp = fopen( binomial_commitment_str, "r" );
    monomial_response_fp = fopen( monomial_response_str, "r" );
    monomial_proof_fp = fopen( monomial_proof_str, "r" );

    if ( XSUCCESS !=
         xrn_check_monomial_proof_from_signature_bytes_wrapper( in_bytes, in_length, xrn_matrix_fp,
                                                                signature_fp, binomial_commitment_fp,
                                                                monomial_response_fp, monomial_proof_fp,
                                                                settings ) ) {

        fclose( xrn_matrix_fp );
        fclose( monomial_key_fp );
        fclose( signature_fp );
        fclose( binomial_commitment_fp );
        fclose( monomial_response_fp );
        fclose( monomial_proof_fp );

        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;

    }

    fclose( xrn_matrix_fp );
    fclose( monomial_key_fp );
    fclose( signature_fp );
    fclose( binomial_commitment_fp );
    fclose( monomial_response_fp );
    fclose( monomial_proof_fp );

    remove( monomial_key_str );
    remove( binomial_key_str );
    remove( xrn_matrix_str );
    remove( monomial_commitment_str );
    remove( binomial_commitment_str );
    remove( monomial_response_str );
    remove( monomial_proof_str );

    return XSUCCESS;

}

int negative_test_verify_signature_bytes_proof(
 )
{

    FILE *binomial_key_fp;
    FILE *monomial_key_fp;
    FILE *xrn_matrix_fp;
    FILE *monomial_commitment_fp;
    FILE *binomial_commitment_fp;
    FILE *monomial_response_fp;
    FILE *monomial_proof_fp;
    FILE *signature_fp;

    char signature_str[256];
    char monomial_key_str[256];
    char binomial_key_str[256];
    char xrn_matrix_str[256];
    char monomial_commitment_str[256];
    char binomial_commitment_str[256];
    char monomial_response_str[256];
    char monomial_proof_str[256];

    xrn_crypto_extra_settings_t settings;

    xbinomial_key_t binomial_key;
    xmonomial_key_t monomial_key;
    xstart_point_t start_point;

    xrn_matrix_t *xm;
    xgenesis_base_t *ob;
    xnum_t cob, cos;

    uint8_t in_bytes[256];
    uint64_t in_length;
    int i;

    for ( i = 0; i < sizeof( settings.encoding_settings.i_settings ); i++ ) {
        ( ( uint8_t * ) & settings.encoding_settings.i_settings )[i] = 0;
    }

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    strcpy( monomial_key_str, "../cache/to_remove_monomial_key.txt" );
    strcpy( binomial_key_str, "../cache/to_remove_binomial_key.txt" );
    strcpy( signature_str, "../cache/to_remove_signature.txt" );
    strcpy( xrn_matrix_str, "../cache/to_remove_xrn_matrix.txt" );
    strcpy( monomial_commitment_str, "../cache/to_remove_monomial_commitment.txt" );
    strcpy( binomial_commitment_str, "../cache/to_remove_binomial_commitment.txt" );
    strcpy( monomial_response_str, "../cache/to_remove_monomial_response.txt" );
    strcpy( monomial_proof_str, "../cache/to_remove_monomial_proof.txt" );

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xrn_matrix_fp = fopen( xrn_matrix_str, "wb" );
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, xrn_matrix_fp, settings );
    fclose( xrn_matrix_fp );

    // load settings

    xrn_load_default_settings( &settings );

    xrn_initialize_rnd_num( &start_point.start );
    xrn_initialize_rnd_num( &monomial_key.distance );
    xrn_make_binomial_key( xm, start_point, monomial_key, &binomial_key, settings );
    free( xm );

    // make monomial key

    monomial_key_fp = fopen( monomial_key_str, "wb" );
    xrn_dump_monomial_key( monomial_key, monomial_key_fp, settings );
    fclose( monomial_key_fp );

    // make binomial key

    binomial_key_fp = fopen( binomial_key_str, "wb" );
    xrn_dump_binomial_key( binomial_key, binomial_key_fp, settings );
    fclose( binomial_key_fp );

    // compute a stream of bytes

    in_length = 256;
    for ( i = 0; i < in_length; i++ ) {
        in_bytes[i] = ( uint8_t ) rand(  ) % 256;
    }

    // compute signature

    monomial_key_fp = fopen( monomial_key_str, "r" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    signature_fp = fopen( signature_str, "w" );

    if ( XSUCCESS !=
         xrn_make_signature_symmetric_bytes_wrapper( in_bytes, in_length, monomial_key_fp, xrn_matrix_fp,
                                                     signature_fp, settings ) ) {

        fclose( monomial_key_fp );
        fclose( xrn_matrix_fp );
        fclose( signature_fp );

        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;

    }

    fclose( monomial_key_fp );
    fclose( xrn_matrix_fp );
    fclose( signature_fp );

    // make binomial commitment

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    signature_fp = fopen( signature_str, "r" );
    monomial_commitment_fp = fopen( monomial_commitment_str, "w" );
    binomial_commitment_fp = fopen( binomial_commitment_str, "w" );

    if ( XSUCCESS !=
         xrn_make_commitment_from_sym_signatures_bytes_wrapper( in_bytes, in_length, xrn_matrix_fp,
                                                                signature_fp, monomial_commitment_fp,
                                                                binomial_commitment_fp, settings ) ) {
        fclose( xrn_matrix_fp );
        fclose( signature_fp );
        fclose( monomial_commitment_fp );
        fclose( binomial_commitment_fp );

        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;
    }

    fclose( xrn_matrix_fp );
    fclose( signature_fp );
    fclose( monomial_commitment_fp );
    fclose( binomial_commitment_fp );

    // add the error;

    in_bytes[rand(  ) % 256]++;

    // make monomial response

    monomial_response_fp = fopen( monomial_response_str, "w" );

    if ( XSUCCESS != xrn_make_monomial_response_wrapper( monomial_response_fp, settings ) ) {
        fclose( monomial_response_fp );
        return 1;
    }

    fclose( monomial_response_fp );

    // make monomial proof

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    monomial_key_fp = fopen( monomial_key_str, "r" );
    binomial_key_fp = fopen( binomial_key_str, "r" );
    monomial_commitment_fp = fopen( monomial_commitment_str, "r" );
    monomial_response_fp = fopen( monomial_response_str, "r" );
    monomial_proof_fp = fopen( monomial_proof_str, "w" );

    if ( XSUCCESS !=
         xrn_make_monomial_proof_wrapper( binomial_key_fp, xrn_matrix_fp, monomial_key_fp,
                                          monomial_commitment_fp, monomial_response_fp, monomial_proof_fp,
                                          settings ) ) {

        fclose( xrn_matrix_fp );
        fclose( monomial_key_fp );
        fclose( binomial_key_fp );
        fclose( monomial_commitment_fp );
        fclose( monomial_response_fp );
        fclose( monomial_proof_fp );

        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;

    }

    fclose( xrn_matrix_fp );
    fclose( binomial_key_fp );
    fclose( monomial_key_fp );
    fclose( monomial_commitment_fp );
    fclose( monomial_response_fp );
    fclose( monomial_proof_fp );

    // check monomial proof

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    monomial_key_fp = fopen( monomial_key_str, "r" );
    signature_fp = fopen( signature_str, "r" );
    binomial_commitment_fp = fopen( binomial_commitment_str, "r" );
    monomial_response_fp = fopen( monomial_response_str, "r" );
    monomial_proof_fp = fopen( monomial_proof_str, "r" );

    if ( XSUCCESS !=
         xrn_check_monomial_proof_from_signature_bytes_wrapper( in_bytes, in_length, xrn_matrix_fp,
                                                                signature_fp, binomial_commitment_fp,
                                                                monomial_response_fp, monomial_proof_fp,
                                                                settings ) ) {

        fclose( xrn_matrix_fp );
        fclose( monomial_key_fp );
        fclose( signature_fp );
        fclose( binomial_commitment_fp );
        fclose( monomial_response_fp );
        fclose( monomial_proof_fp );

        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;

    }

    fclose( xrn_matrix_fp );
    fclose( monomial_key_fp );
    fclose( signature_fp );
    fclose( binomial_commitment_fp );
    fclose( monomial_response_fp );
    fclose( monomial_proof_fp );

    remove( monomial_key_str );
    remove( binomial_key_str );
    remove( xrn_matrix_str );
    remove( monomial_commitment_str );
    remove( binomial_commitment_str );
    remove( monomial_response_str );
    remove( monomial_proof_str );

    return XSUCCESS;

}

int test_verify_signature_proof(
 )
{

    FILE *binomial_key_fp;
    FILE *monomial_key_fp;
    FILE *xrn_matrix_fp;
    FILE *monomial_commitment_fp;
    FILE *binomial_commitment_fp;
    FILE *monomial_response_fp;
    FILE *monomial_proof_fp;
    FILE *signature_fp;
    FILE *message_fp;

    char message_str[256];
    char signature_str[256];
    char monomial_key_str[256];
    char binomial_key_str[256];
    char xrn_matrix_str[256];
    char monomial_commitment_str[256];
    char binomial_commitment_str[256];
    char monomial_response_str[256];
    char monomial_proof_str[256];

    xrn_crypto_extra_settings_t settings;

    xbinomial_key_t binomial_key;
    xmonomial_key_t monomial_key;
    xstart_point_t start_point;

    xrn_matrix_t *xm;
    xgenesis_base_t *ob;
    xnum_t cob, cos;

    uint8_t in_bytes[256];
    uint64_t in_length;
    int i;

    for ( i = 0; i < sizeof( settings.encoding_settings.i_settings ); i++ ) {
        ( ( uint8_t * ) & settings.encoding_settings.i_settings )[i] = 0;
    }

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    strcpy( message_str, "../cache/to_remove_message.txt" );
    strcpy( monomial_key_str, "../cache/to_remove_monomial_key.txt" );
    strcpy( binomial_key_str, "../cache/to_remove_binomial_key.txt" );
    strcpy( signature_str, "../cache/to_remove_signature.txt" );
    strcpy( xrn_matrix_str, "../cache/to_remove_xrn_matrix.txt" );
    strcpy( monomial_commitment_str, "../cache/to_remove_monomial_commitment.txt" );
    strcpy( binomial_commitment_str, "../cache/to_remove_binomial_commitment.txt" );
    strcpy( monomial_response_str, "../cache/to_remove_monomial_response.txt" );
    strcpy( monomial_proof_str, "../cache/to_remove_monomial_proof.txt" );

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xrn_matrix_fp = fopen( xrn_matrix_str, "wb" );
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, xrn_matrix_fp, settings );
    fclose( xrn_matrix_fp );

    // load settings

    xrn_load_default_settings( &settings );

    xrn_initialize_rnd_num( &start_point.start );
    xrn_initialize_rnd_num( &monomial_key.distance );
    xrn_make_binomial_key( xm, start_point, monomial_key, &binomial_key, settings );
    free( xm );

    // make monomial key

    monomial_key_fp = fopen( monomial_key_str, "wb" );
    xrn_dump_monomial_key( monomial_key, monomial_key_fp, settings );
    fclose( monomial_key_fp );

    // make binomial key

    binomial_key_fp = fopen( binomial_key_str, "wb" );
    xrn_dump_binomial_key( binomial_key, binomial_key_fp, settings );
    fclose( binomial_key_fp );

    // compute a stream of bytes

    in_length = 256;
    for ( i = 0; i < in_length; i++ ) {
        in_bytes[i] = ( uint8_t ) rand(  ) % 256;
    }

    // store in a file

    message_fp = fopen( message_str, "wb" );
    fwrite( in_bytes, in_length, 1, message_fp );
    fclose( message_fp );

    // compute signature

    message_fp = fopen( message_str, "rb" );
    monomial_key_fp = fopen( monomial_key_str, "r" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    signature_fp = fopen( signature_str, "w" );

    if ( XSUCCESS !=
         xrn_make_signature_symmetric_wrapper( message_fp, monomial_key_fp, xrn_matrix_fp, signature_fp,
                                               settings ) ) {

        fclose( message_fp );
        fclose( monomial_key_fp );
        fclose( xrn_matrix_fp );
        fclose( signature_fp );

        remove( message_str );
        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;

    }

    fclose( message_fp );
    fclose( monomial_key_fp );
    fclose( xrn_matrix_fp );
    fclose( signature_fp );

    // make binomial commitment

    message_fp = fopen( message_str, "rb" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    signature_fp = fopen( signature_str, "r" );
    monomial_commitment_fp = fopen( monomial_commitment_str, "w" );
    binomial_commitment_fp = fopen( binomial_commitment_str, "w" );

    if ( XSUCCESS !=
         xrn_make_commitment_from_sym_signatures_wrapper( message_fp, xrn_matrix_fp, signature_fp,
                                                          monomial_commitment_fp, binomial_commitment_fp,
                                                          settings ) ) {

        fclose( message_fp );
        fclose( xrn_matrix_fp );
        fclose( signature_fp );
        fclose( monomial_commitment_fp );
        fclose( binomial_commitment_fp );

        remove( message_str );
        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;
    }

    fclose( message_fp );
    fclose( xrn_matrix_fp );
    fclose( signature_fp );
    fclose( monomial_commitment_fp );
    fclose( binomial_commitment_fp );

    // make monomial response

    monomial_response_fp = fopen( monomial_response_str, "w" );

    if ( XSUCCESS != xrn_make_monomial_response_wrapper( monomial_response_fp, settings ) ) {
        fclose( monomial_response_fp );
        return 1;
    }

    fclose( monomial_response_fp );

    // make monomial proof

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    monomial_key_fp = fopen( monomial_key_str, "r" );
    monomial_commitment_fp = fopen( monomial_commitment_str, "r" );
    monomial_response_fp = fopen( monomial_response_str, "r" );
    monomial_proof_fp = fopen( monomial_proof_str, "w" );
    message_fp = fopen( message_str, "rb" );
    signature_fp = fopen( signature_str, "r" );

    if ( XSUCCESS !=
         xrn_make_monomial_proof_from_signature_wrapper( message_fp, xrn_matrix_fp, signature_fp,
                                                         monomial_key_fp, monomial_commitment_fp,
                                                         monomial_response_fp, monomial_proof_fp,
                                                         settings ) ) {

        fclose( xrn_matrix_fp );
        fclose( message_fp );
        fclose( signature_fp );
        fclose( monomial_key_fp );
        fclose( monomial_commitment_fp );
        fclose( monomial_response_fp );
        fclose( monomial_proof_fp );

        remove( message_str );
        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;

    }

    fclose( signature_fp );
    fclose( message_fp );
    fclose( xrn_matrix_fp );
    fclose( monomial_key_fp );
    fclose( monomial_commitment_fp );
    fclose( monomial_response_fp );
    fclose( monomial_proof_fp );

    // check monomial proof

    message_fp = fopen( message_str, "rb" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    monomial_key_fp = fopen( monomial_key_str, "r" );
    signature_fp = fopen( signature_str, "r" );
    binomial_commitment_fp = fopen( binomial_commitment_str, "r" );
    monomial_response_fp = fopen( monomial_response_str, "r" );
    monomial_proof_fp = fopen( monomial_proof_str, "r" );

    if ( XSUCCESS !=
         xrn_check_monomial_proof_from_signature_wrapper( message_fp, xrn_matrix_fp, signature_fp,
                                                          binomial_commitment_fp, monomial_response_fp,
                                                          monomial_proof_fp, settings ) ) {

        fclose( message_fp );
        fclose( xrn_matrix_fp );
        fclose( monomial_key_fp );
        fclose( signature_fp );
        fclose( binomial_commitment_fp );
        fclose( monomial_response_fp );
        fclose( monomial_proof_fp );

        remove( message_str );
        remove( monomial_key_str );
        remove( binomial_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );

        return 1;

    }

    fclose( message_fp );
    fclose( xrn_matrix_fp );
    fclose( monomial_key_fp );
    fclose( signature_fp );
    fclose( binomial_commitment_fp );
    fclose( monomial_response_fp );
    fclose( monomial_proof_fp );

    remove( message_str );
    remove( monomial_key_str );
    remove( binomial_key_str );
    remove( xrn_matrix_str );
    remove( monomial_commitment_str );
    remove( binomial_commitment_str );
    remove( monomial_response_str );
    remove( monomial_proof_str );

    return XSUCCESS;

}

int test_verify_certificate_proof(
 )
{

    FILE *monovalent_key_fp;
    FILE *monovalent_key_2_fp;
    FILE *monomial_key_fp;
    FILE *xrn_matrix_fp;
    FILE *monomial_commitment_fp;
    FILE *binomial_commitment_fp;
    FILE *monomial_response_fp;
    FILE *monomial_proof_fp;
    FILE *certificate_fp;

    char monomial_key_str[256];
    char monovalent_key_str[256];
    char xrn_matrix_str[256];
    char monomial_commitment_str[256];
    char binomial_commitment_str[256];
    char monomial_response_str[256];
    char monomial_proof_str[256];
    char certificate_str[256];

    xrn_crypto_extra_settings_t settings;

    xmonovalent_key_t monovalent_key;
    xpolyvalent_key_t polyvalent_key;
    xpolyvalent_proof_t polyvalent_proof;
    xmonomial_key_t monomial_key;

    xrn_matrix_t *xm;
    xgenesis_base_t *ob;
    xnum_t cob, cos;
    int i;

    for ( i = 0; i < sizeof( settings.encoding_settings.i_settings ); i++ ) {
        ( ( uint8_t * ) & settings.encoding_settings.i_settings )[i] = 0;
    }

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    strcpy( certificate_str, "../cache/to_remove_certificate.txt" );
    strcpy( monomial_key_str, "../cache/to_remove_monomial_key.txt" );
    strcpy( monovalent_key_str, "../cache/to_remove_monovalent_key.txt" );
    strcpy( xrn_matrix_str, "../cache/to_remove_xrn_matrix.txt" );
    strcpy( monomial_commitment_str, "../cache/to_remove_monomial_commitment.txt" );
    strcpy( binomial_commitment_str, "../cache/to_remove_binomial_commitment.txt" );
    strcpy( monomial_response_str, "../cache/to_remove_monomial_response.txt" );
    strcpy( monomial_proof_str, "../cache/to_remove_monomial_proof.txt" );

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix

    xrn_matrix_fp = fopen( xrn_matrix_str, "wb" );
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, xrn_matrix_fp, settings );
    fclose( xrn_matrix_fp );

    // load settings

    xrn_load_default_settings( &settings );

    xrn_initialize_rnd_num( &monomial_key.distance );
    xrn_make_monovalent_key( xm, 0, 0xffffffffffffffff, &polyvalent_key, &polyvalent_proof, &monovalent_key,
                             settings );
    free( xm );

    // make monomial key

    monomial_key_fp = fopen( monomial_key_str, "wb" );
    xrn_dump_monomial_key( monomial_key, monomial_key_fp, settings );
    fclose( monomial_key_fp );

    // make monovalent key

    monovalent_key_fp = fopen( monovalent_key_str, "wb" );
    xrn_dump_monovalent_key( monovalent_key, monovalent_key_fp, settings );
    fclose( monovalent_key_fp );

    // make certificate

    monovalent_key_2_fp = fopen( monovalent_key_str, "r" );
    monomial_key_fp = fopen( monomial_key_str, "r" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    certificate_fp = fopen( certificate_str, "w" );

    if ( XSUCCESS !=
         xrn_make_certificate_symmetric_wrapper( monomial_key_fp, monovalent_key_2_fp, "BOB", xrn_matrix_fp,
                                                 0, 10, certificate_fp, settings ) ) {

        fclose( monomial_key_fp );
        fclose( monovalent_key_2_fp );
        fclose( xrn_matrix_fp );
        fclose( certificate_fp );

        remove( monomial_key_str );
        remove( monovalent_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );
        remove( certificate_str );

        return 1;
    }

    fclose( monomial_key_fp );
    fclose( monovalent_key_2_fp );
    fclose( xrn_matrix_fp );
    fclose( certificate_fp );

    // make binomial commitment

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    certificate_fp = fopen( certificate_str, "r" );
    monomial_commitment_fp = fopen( monomial_commitment_str, "w" );
    binomial_commitment_fp = fopen( binomial_commitment_str, "w" );

    if ( XSUCCESS !=
         xrn_make_commitment_from_sym_certificate_wrapper( certificate_fp, xrn_matrix_fp,
                                                           monomial_commitment_fp, binomial_commitment_fp,
                                                           settings ) ) {
        fclose( xrn_matrix_fp );
        fclose( certificate_fp );
        fclose( monomial_commitment_fp );
        fclose( binomial_commitment_fp );

        remove( monomial_key_str );
        remove( monovalent_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );
        remove( certificate_str );

        return 1;
    }

    fclose( xrn_matrix_fp );
    fclose( certificate_fp );
    fclose( monomial_commitment_fp );
    fclose( binomial_commitment_fp );

    // make monomial response

    monomial_response_fp = fopen( monomial_response_str, "w" );

    if ( XSUCCESS != xrn_make_monomial_response_wrapper( monomial_response_fp, settings ) ) {
        fclose( monomial_response_fp );
        return 1;
    }

    fclose( monomial_response_fp );

    // make monomial proof

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    monomial_key_fp = fopen( monomial_key_str, "r" );
    monomial_commitment_fp = fopen( monomial_commitment_str, "r" );
    monomial_response_fp = fopen( monomial_response_str, "r" );
    certificate_fp = fopen( certificate_str, "r" );
    monomial_proof_fp = fopen( monomial_proof_str, "w" );

    if ( XSUCCESS !=
         xrn_make_monomial_proof_from_sym_certificate_wrapper( xrn_matrix_fp, certificate_fp,
                                                               monomial_key_fp, monomial_commitment_fp,
                                                               monomial_response_fp, monomial_proof_fp,
                                                               settings ) ) {

        fclose( certificate_fp );
        fclose( xrn_matrix_fp );
        fclose( monomial_key_fp );
        fclose( monomial_commitment_fp );
        fclose( monomial_response_fp );
        fclose( monomial_proof_fp );

        remove( monomial_key_str );
        remove( monovalent_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );
        remove( certificate_str );

        return 1;

    }

    fclose( certificate_fp );
    fclose( xrn_matrix_fp );
    fclose( monomial_key_fp );
    fclose( monomial_commitment_fp );
    fclose( monomial_response_fp );
    fclose( monomial_proof_fp );

    // check monomial proof

    certificate_fp = fopen( certificate_str, "r" );
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    monomial_key_fp = fopen( monomial_key_str, "r" );
    binomial_commitment_fp = fopen( binomial_commitment_str, "r" );
    monomial_response_fp = fopen( monomial_response_str, "r" );
    monomial_proof_fp = fopen( monomial_proof_str, "r" );

    if ( XSUCCESS !=
         xrn_check_monomial_proof_from_certificate_wrapper( certificate_fp, xrn_matrix_fp,
                                                            binomial_commitment_fp, monomial_response_fp,
                                                            monomial_proof_fp, settings ) ) {

        fclose( certificate_fp );
        fclose( xrn_matrix_fp );
        fclose( monomial_key_fp );
        fclose( binomial_commitment_fp );
        fclose( monomial_response_fp );
        fclose( monomial_proof_fp );

        remove( monomial_key_str );
        remove( monovalent_key_str );
        remove( xrn_matrix_str );
        remove( monomial_commitment_str );
        remove( binomial_commitment_str );
        remove( monomial_response_str );
        remove( monomial_proof_str );
        remove( certificate_str );

        return 1;

    }

    fclose( certificate_fp );
    fclose( xrn_matrix_fp );
    fclose( monomial_key_fp );
    fclose( binomial_commitment_fp );
    fclose( monomial_response_fp );
    fclose( monomial_proof_fp );

    remove( certificate_str );
    remove( monomial_key_str );
    remove( monovalent_key_str );
    remove( xrn_matrix_str );
    remove( monomial_commitment_str );
    remove( binomial_commitment_str );
    remove( monomial_response_str );
    remove( monomial_proof_str );

    return XSUCCESS;

}

int test_matrix_compressed_key_permute(
 )
{

    xrn_crypto_extra_settings_t settings;
    xmonomial_key_t mkey;
    int i;

    xrn_matrix_t *xm;
    xrn_matrix_compressed_t xmc, xmc2;
    xgenesis_base_t *ob;
    xnum_t cob, cos;

    FILE *xrn_matrix_compressed_fpr;
    FILE *xrn_matrix_fpr;
    FILE *mkey_fp;
    FILE *xrn_matrix_compressed_fpw;

    char mkey_str[256];
    char xrn_matrix_compressed_fpr_str[256];
    char xrn_matrix_fpr_str[256];
    char xrn_matrix_compressed_fpw_str0[256];
    char xrn_matrix_compressed_fpw_str1[256];

    strcpy( mkey_str, "../cache/to_remove_xrn_monomial_key_fpr_str.txt" );
    strcpy( xrn_matrix_compressed_fpr_str, "../cache/to_remove_xrn_matrix_compressed_fpr_str.txt" );
    strcpy( xrn_matrix_fpr_str, "../cache/to_remove_xrn_matrix_fpr_str.txt" );
    strcpy( xrn_matrix_compressed_fpw_str0, "../cache/to_remove_xrn_matrix_compressed_fpw_str0.txt" );
    strcpy( xrn_matrix_compressed_fpw_str1, "../cache/to_remove_xrn_matrix_compressed_fpw_str1.txt" );

    xrn_load_default_settings( &settings );

    for ( i = 0; i < sizeof( xmc ); i++ ) {
        ( ( uint8_t * ) & xmc )[i] = 0;
        ( ( uint8_t * ) & xmc2 )[i] = 0;
    }

    mkey_fp = fopen( mkey_str, "wb" );
    xrn_initialize_rnd_num( &mkey.distance );
    xrn_dump_monomial_key( mkey, mkey_fp, settings );
    fclose( mkey_fp );

    // generate origin base

    xrn_matrix_compressed_fpr = fopen( xrn_matrix_compressed_fpr_str, "wb" );
    xrn_matrix_fpr = fopen( xrn_matrix_fpr_str, "wb" );
    ob = ( xgenesis_base_t * ) malloc( sizeof( uint8_t ) * sizeof( xgenesis_base_t ) );
    xm = ( xrn_matrix_t * ) malloc( sizeof( uint8_t ) * sizeof( xrn_matrix_t ) );

    xgenesis_base_init( ob );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign

    xmc.change_of_sign = cos;
    xmc.change_of_base = cob;
    xmc.xgenesis_base = ( *ob );

    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );

    xrn_dump_matrix_compressed( &xmc, xrn_matrix_compressed_fpr, settings );
    xrn_dump_matrix( xm, xrn_matrix_fpr, settings );

    fclose( xrn_matrix_compressed_fpr );
    fclose( xrn_matrix_fpr );

    free( ob );
    free( xm );

    mkey_fp = fopen( mkey_str, "rb" );
    xrn_matrix_fpr = fopen( xrn_matrix_fpr_str, "rb" );
    xrn_matrix_compressed_fpr = fopen( xrn_matrix_compressed_fpr_str, "rb" );
    xrn_matrix_compressed_fpw = fopen( xrn_matrix_compressed_fpw_str0, "wb" );
    if ( XSUCCESS !=
         xrn_permute_matrix_compressed_key_wrapper( xrn_matrix_compressed_fpr,
                                                    xrn_matrix_fpr,
                                                    mkey_fp, xrn_matrix_compressed_fpw, settings ) ) {
        fclose( mkey_fp );
        fclose( xrn_matrix_fpr );
        fclose( xrn_matrix_compressed_fpr );
        fclose( xrn_matrix_compressed_fpw );
        remove( mkey_str );
        remove( xrn_matrix_compressed_fpr_str );
        remove( xrn_matrix_fpr_str );
        remove( xrn_matrix_compressed_fpw_str0 );
        remove( xrn_matrix_compressed_fpw_str1 );
        return 1;
    }

    fclose( xrn_matrix_fpr );
    fclose( mkey_fp );
    fclose( xrn_matrix_compressed_fpr );
    fclose( xrn_matrix_compressed_fpw );

    xrn_matrix_fpr = fopen( xrn_matrix_fpr_str, "rb" );
    mkey_fp = fopen( mkey_str, "rb" );
    xrn_matrix_compressed_fpr = fopen( xrn_matrix_compressed_fpr_str, "rb" );
    xrn_matrix_compressed_fpw = fopen( xrn_matrix_compressed_fpw_str1, "wb" );
    if ( XSUCCESS !=
         xrn_permute_matrix_compressed_key_wrapper( xrn_matrix_compressed_fpr,
                                                    xrn_matrix_fpr, mkey_fp,
                                                    xrn_matrix_compressed_fpw, settings ) ) {
        fclose( xrn_matrix_fpr );
        fclose( xrn_matrix_compressed_fpr );
        fclose( xrn_matrix_compressed_fpw );
        fclose( mkey_fp );
        remove( mkey_str );
        remove( xrn_matrix_compressed_fpr_str );
        remove( xrn_matrix_fpr_str );
        remove( xrn_matrix_compressed_fpw_str0 );
        remove( xrn_matrix_compressed_fpw_str1 );
        return 1;
    }

    fclose( xrn_matrix_fpr );
    fclose( xrn_matrix_compressed_fpr );
    fclose( xrn_matrix_compressed_fpw );
    fclose( mkey_fp );

    xrn_matrix_compressed_fpw = fopen( xrn_matrix_compressed_fpw_str0, "rb" );
    if ( XSUCCESS != xrn_load_matrix_compressed( xrn_matrix_compressed_fpw, &xmc, settings ) ) {
        fclose( xrn_matrix_compressed_fpw );
        remove( mkey_str );
        remove( xrn_matrix_compressed_fpr_str );
        remove( xrn_matrix_fpr_str );
        remove( xrn_matrix_compressed_fpw_str0 );
        remove( xrn_matrix_compressed_fpw_str1 );
        return 1;
    }

    fclose( xrn_matrix_compressed_fpw );

    xrn_matrix_compressed_fpw = fopen( xrn_matrix_compressed_fpw_str1, "rb" );
    if ( XSUCCESS != xrn_load_matrix_compressed( xrn_matrix_compressed_fpw, &xmc2, settings ) ) {
        fclose( xrn_matrix_compressed_fpw );
        remove( mkey_str );
        remove( xrn_matrix_compressed_fpr_str );
        remove( xrn_matrix_fpr_str );
        remove( xrn_matrix_compressed_fpw_str0 );
        remove( xrn_matrix_compressed_fpw_str1 );
        return 1;
    }

    fclose( xrn_matrix_compressed_fpw );

    remove( mkey_str );
    remove( xrn_matrix_compressed_fpr_str );
    remove( xrn_matrix_fpr_str );
    remove( xrn_matrix_compressed_fpw_str0 );
    remove( xrn_matrix_compressed_fpw_str1 );

    if ( xrn_compare_matrices_compressed( &xmc, &xmc2 ) == XNOT_EQUAL ) {
        return 1;
    }

    return XSUCCESS;

}

int test_matrix_compressed_deterministic_permute(
 )
{

    xrn_crypto_extra_settings_t settings;

    xrn_matrix_t *xm;
    xrn_matrix_compressed_t xmc, xmc2;
    xgenesis_base_t *ob;
    xnum_t cob, cos;
    int i;

    FILE *xrn_matrix_compressed_fpr;
    FILE *xrn_matrix_fpr;
    FILE *xrn_matrix_compressed_fpw;

    char xrn_matrix_compressed_fpr_str[256];
    char xrn_matrix_fpr_str[256];
    char xrn_matrix_compressed_fpw_str0[256];
    char xrn_matrix_compressed_fpw_str1[256];

    strcpy( xrn_matrix_compressed_fpr_str, "../cache/to_remove_xrn_matrix_compressed_fpr_str.txt" );
    strcpy( xrn_matrix_fpr_str, "../cache/to_remove_xrn_matrix_fpr_str.txt" );
    strcpy( xrn_matrix_compressed_fpw_str0, "../cache/to_remove_xrn_matrix_compressed_fpw_str0.txt" );
    strcpy( xrn_matrix_compressed_fpw_str1, "../cache/to_remove_xrn_matrix_compressed_fpw_str1.txt" );

    for ( i = 0; i < sizeof( xmc ); i++ ) {
        ( ( uint8_t * ) & xmc )[i] = 0;
        ( ( uint8_t * ) & xmc2 )[i] = 0;
    }

    xrn_load_default_settings( &settings );

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xrn_matrix_compressed_fpr = fopen( xrn_matrix_compressed_fpr_str, "wb" );
    xmc.change_of_sign = cos;
    xmc.change_of_base = cob;
    xmc.xgenesis_base = ( *ob );
    xrn_dump_matrix_compressed( &xmc, xrn_matrix_compressed_fpr, settings );
    fclose( xrn_matrix_compressed_fpr );

    xrn_matrix_fpr = fopen( xrn_matrix_fpr_str, "wb" );
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xmc.xgenesis_base = ( *ob );
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    xrn_dump_matrix( xm, xrn_matrix_fpr, settings );
    fclose( xrn_matrix_fpr );

    free( ob );
    free( xm );

    xrn_matrix_fpr = fopen( xrn_matrix_fpr_str, "rb" );
    xrn_matrix_compressed_fpr = fopen( xrn_matrix_compressed_fpr_str, "rb" );
    xrn_matrix_compressed_fpw = fopen( xrn_matrix_compressed_fpw_str0, "wb" );
    if ( XSUCCESS !=
         xrn_permute_matrix_compressed_deterministically_wrapper( xrn_matrix_compressed_fpr, xrn_matrix_fpr,
                                                                  xrn_matrix_compressed_fpw, settings ) ) {
        fclose( xrn_matrix_fpr );
        fclose( xrn_matrix_compressed_fpr );
        fclose( xrn_matrix_compressed_fpw );
        return 1;
    }

    fclose( xrn_matrix_fpr );
    fclose( xrn_matrix_compressed_fpr );
    fclose( xrn_matrix_compressed_fpw );

    xrn_matrix_fpr = fopen( xrn_matrix_fpr_str, "rb" );
    xrn_matrix_compressed_fpr = fopen( xrn_matrix_compressed_fpr_str, "rb" );
    xrn_matrix_compressed_fpw = fopen( xrn_matrix_compressed_fpw_str1, "wb" );
    if ( XSUCCESS !=
         xrn_permute_matrix_compressed_deterministically_wrapper( xrn_matrix_compressed_fpr, xrn_matrix_fpr,
                                                                  xrn_matrix_compressed_fpw, settings ) ) {
        fclose( xrn_matrix_fpr );
        fclose( xrn_matrix_compressed_fpr );
        fclose( xrn_matrix_compressed_fpw );
        remove( xrn_matrix_compressed_fpr_str );
        remove( xrn_matrix_fpr_str );
        remove( xrn_matrix_compressed_fpw_str0 );
        remove( xrn_matrix_compressed_fpw_str1 );

        return 1;
    }

    fclose( xrn_matrix_fpr );
    fclose( xrn_matrix_compressed_fpr );
    fclose( xrn_matrix_compressed_fpw );

    xrn_matrix_compressed_fpw = fopen( xrn_matrix_compressed_fpw_str0, "rb" );
    if ( XSUCCESS != xrn_load_matrix_compressed( xrn_matrix_compressed_fpw, &xmc, settings ) ) {
        fclose( xrn_matrix_compressed_fpw );
        remove( xrn_matrix_compressed_fpr_str );
        remove( xrn_matrix_fpr_str );
        remove( xrn_matrix_compressed_fpw_str0 );
        remove( xrn_matrix_compressed_fpw_str1 );
        return 1;
    }

    fclose( xrn_matrix_compressed_fpw );

    xrn_matrix_compressed_fpw = fopen( xrn_matrix_compressed_fpw_str1, "rb" );
    if ( XSUCCESS != xrn_load_matrix_compressed( xrn_matrix_compressed_fpw, &xmc2, settings ) ) {
        fclose( xrn_matrix_compressed_fpw );
        remove( xrn_matrix_compressed_fpr_str );
        remove( xrn_matrix_fpr_str );
        remove( xrn_matrix_compressed_fpw_str0 );
        remove( xrn_matrix_compressed_fpw_str1 );
        return 1;
    }

    fclose( xrn_matrix_compressed_fpw );

    remove( xrn_matrix_compressed_fpr_str );
    remove( xrn_matrix_fpr_str );
    remove( xrn_matrix_compressed_fpw_str0 );
    remove( xrn_matrix_compressed_fpw_str1 );

    if ( xrn_compare_matrices_compressed( &xmc, &xmc2 ) == XNOT_EQUAL ) {

        return 1;
    }

    return XSUCCESS;

}

int test_encoder(
 )
{

    FILE *input_file_fp, *encoded_file_fp, *decoded_file_fp;
    xrn_crypto_extra_settings_t settings;
    char input_file_str[256], encoded_file_str[256], decoded_file_str[256];
    int error, cnt0, cnt1, ret;
    uint8_t ch1, ch2;
    int i, file_size;
    uint8_t num8;

    strcpy( input_file_str, "../cache/to_remove_input_file.txt" );
    strcpy( encoded_file_str, "../cache/to_remove_encoded_file.txt" );
    strcpy( decoded_file_str, "../cache/to_remove_decoded_file.txt" );

    xrn_load_default_settings( &settings );

    input_file_fp = fopen( input_file_str, "wb" );
    file_size = rand(  ) % 1600;
    for ( i = 0; i < file_size; i++ ) {
        num8 = ( uint8_t ) rand(  ) % 256;
        fwrite( &num8, sizeof( uint8_t ), 1, input_file_fp );
    }

    fclose( input_file_fp );

    input_file_fp = fopen( input_file_str, "rb" );
    encoded_file_fp = fopen( encoded_file_str, "wb" );
    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = no_encoding;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;
    ret = xrn_decode_encode_wrapper( input_file_fp, encoded_file_fp, settings );
    if ( ret != XSUCCESS ) {
        fclose( input_file_fp );
        fclose( encoded_file_fp );
        remove( input_file_str );
        remove( encoded_file_str );
        remove( decoded_file_str );
        return 1;
    }

    fclose( input_file_fp );
    fclose( encoded_file_fp );

    encoded_file_fp = fopen( encoded_file_str, "rb" );
    decoded_file_fp = fopen( decoded_file_str, "wb" );

    xrn_load_default_settings( &settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = no_encoding;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;
    ret = xrn_decode_encode_wrapper( encoded_file_fp, decoded_file_fp, settings );
    if ( ret != XSUCCESS ) {
        fclose( decoded_file_fp );
        fclose( encoded_file_fp );
        remove( input_file_str );
        remove( encoded_file_str );
        remove( decoded_file_str );
        return 1;
    }

    fclose( decoded_file_fp );
    fclose( encoded_file_fp );

    // compare the two files

    input_file_fp = fopen( input_file_str, "rb" );
    decoded_file_fp = fopen( decoded_file_str, "rb" );

    error = 0;
    do {
        // Input character from both files
        cnt0 = ( int ) fread( &ch1, sizeof( uint8_t ), 1, input_file_fp );
        cnt1 = ( int ) fread( &ch2, sizeof( uint8_t ), 1, decoded_file_fp );
        error = ( ( ch1 != ch2 ) || ( cnt0 != cnt1 ) ) || error;

    } while ( cnt0 != 0 && cnt1 != 0 );

    fclose( input_file_fp );
    fclose( decoded_file_fp );

    remove( input_file_str );
    remove( encoded_file_str );
    remove( decoded_file_str );

    if ( error == 1 ) {
        return 1;
    }

    return XSUCCESS;

}

int test_encoder_bytes(
 )
{

    uint8_t in_bytes[1600], enc_bytes[1600], dec_bytes[1600];
    xrn_crypto_extra_settings_t settings;
    int error, ret;
    int i;
    uint64_t file_size;
    uint8_t num8;

    file_size = ( uint64_t ) ( rand(  ) % 1600 );
    for ( i = 0; i < file_size; i++ ) {
        num8 = ( uint8_t ) rand(  ) % 256;
        in_bytes[i] = num8;
    }

    xrn_load_default_settings( &settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.mode = no_encoding;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;
    ret = xrn_decode_encode_bytes_wrapper( in_bytes, enc_bytes, file_size, settings );
    if ( ret != XSUCCESS ) {
        return 1;
    }

    xrn_load_default_settings( &settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = no_encoding;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;
    ret = xrn_decode_encode_bytes_wrapper( enc_bytes, dec_bytes, file_size, settings );
    if ( ret != XSUCCESS ) {
        return 1;
    }

    // compare the stream of bytes
    error = 0;
    for ( i = 0; i < file_size; i++ ) {
        error = in_bytes[i] != dec_bytes[i];
    }

    if ( error == 1 ) {
        return 1;
    }

    return XSUCCESS;

}

int test_xrn_exchange_polyvalent_key(
 )
{

    FILE *xrn_matrix_fp;
    FILE *alice_monovalent_key_fp;
    FILE *bob_monovalent_key_fp;
    FILE *alice_polyvalent_key_fp;
    FILE *alice_polyvalent_proof_fp;
    FILE *bob_polyvalent_key_fp;
    FILE *bob_polyvalent_proof_fp;
    FILE *alice_shared_polyvalent_key_fp;
    FILE *bob_shared_polyvalent_key_fp;
    char xrn_matrix_str[256];
    char alice_monovalent_key_str[256];
    char bob_monovalent_key_str[256];
    char alice_polyvalent_key_str[256];
    char alice_polyvalent_proof_str[256];
    char alice_shared_polyvalent_key_str[256];
    char bob_polyvalent_key_str[256];
    char bob_polyvalent_proof_str[256];
    char bob_shared_polyvalent_key_str[256];
    xpolyvalent_key_t shared_alice;
    xpolyvalent_key_t shared_bob;

    uint64_t end_timestamp, start_timestamp;
    int i, ret, error;

    xnum_t cob, cos;
    xgenesis_base_t *ob;
    xrn_matrix_t *xm;
    xrn_crypto_extra_settings_t settings;

    xrn_load_default_settings( &settings );
    settings.const_exec_time = ( uint8_t ) rand(  ) % 2;
    settings.thread_enable = ( uint8_t ) rand(  ) % 2;

    strcpy( xrn_matrix_str, "../cache/to_remove_load_monovalent_matrix.txt" );
    strcpy( alice_monovalent_key_str, "../cache/to_remove_load_monovalent_alimonovalent.txt" );
    strcpy( alice_polyvalent_key_str, "../cache/to_remove_load_monovalent_alipolykey.txt" );
    strcpy( alice_polyvalent_proof_str, "../cache/to_remove_load_monovalent_alipolyproof.txt" );
    strcpy( bob_monovalent_key_str, "../cache/to_remove_load_monovalent_bobmonovalent.txt" );
    strcpy( bob_polyvalent_key_str, "../cache/to_remove_load_monovalent_bobpolykey.txt" );
    strcpy( bob_polyvalent_proof_str, "../cache/to_remove_load_monovalent_bobpolyproof.txt" );
    strcpy( alice_shared_polyvalent_key_str, "../cache/to_remove_load_shared_alice_poly_key.txt" );
    strcpy( bob_shared_polyvalent_key_str, "../cache/to_remove_load_shared_bob_poly_key.txt" );

    // generate xoron matrix
    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_init( ob );
    xrn_matrix_fp = fopen( xrn_matrix_str, "wb" );
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, xrn_matrix_fp, settings );
    free( xm );
    fclose( xrn_matrix_fp );

    // make time stamps

    time( ( time_t * ) & start_timestamp );
    end_timestamp = start_timestamp + 3000;

    // make monovalent key alice

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    alice_polyvalent_key_fp = fopen( alice_polyvalent_key_str, "wb" );
    alice_polyvalent_proof_fp = fopen( alice_polyvalent_proof_str, "wb" );
    alice_monovalent_key_fp = fopen( alice_monovalent_key_str, "wb" );

    ret =
        xrn_make_monovalent_key_wrapper( xrn_matrix_fp, start_timestamp, end_timestamp,
                                         alice_polyvalent_key_fp, alice_polyvalent_proof_fp,
                                         alice_monovalent_key_fp, settings );
    if ( ret != XSUCCESS ) {

        fclose( xrn_matrix_fp );
        fclose( alice_polyvalent_key_fp );
        fclose( alice_polyvalent_proof_fp );
        fclose( alice_monovalent_key_fp );

        remove( xrn_matrix_str );
        remove( alice_monovalent_key_str );
        remove( alice_polyvalent_key_str );
        remove( alice_polyvalent_proof_str );
        remove( bob_monovalent_key_str );
        remove( bob_polyvalent_key_str );
        remove( bob_polyvalent_proof_str );
        remove( alice_shared_polyvalent_key_str );
        remove( bob_shared_polyvalent_key_str );

        return 1;

    }

    fclose( xrn_matrix_fp );
    fclose( alice_polyvalent_key_fp );
    fclose( alice_polyvalent_proof_fp );
    fclose( alice_monovalent_key_fp );

    // make monovalent key bob

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    bob_polyvalent_key_fp = fopen( bob_polyvalent_key_str, "wb" );
    bob_polyvalent_proof_fp = fopen( bob_polyvalent_proof_str, "wb" );
    bob_monovalent_key_fp = fopen( bob_monovalent_key_str, "wb" );

    ret =
        xrn_make_monovalent_key_wrapper( xrn_matrix_fp, start_timestamp, end_timestamp, bob_polyvalent_key_fp,
                                         bob_polyvalent_proof_fp, bob_monovalent_key_fp, settings );
    if ( ret != XSUCCESS ) {

        fclose( xrn_matrix_fp );
        fclose( bob_polyvalent_key_fp );
        fclose( bob_polyvalent_proof_fp );
        fclose( bob_monovalent_key_fp );

        remove( xrn_matrix_str );
        remove( alice_monovalent_key_str );
        remove( alice_polyvalent_key_str );
        remove( alice_polyvalent_proof_str );
        remove( bob_monovalent_key_str );
        remove( bob_polyvalent_key_str );
        remove( bob_polyvalent_proof_str );
        remove( alice_shared_polyvalent_key_str );
        remove( bob_shared_polyvalent_key_str );

        return 1;
    }

    fclose( xrn_matrix_fp );
    fclose( bob_polyvalent_key_fp );
    fclose( bob_polyvalent_proof_fp );
    fclose( bob_monovalent_key_fp );

    // key exchange alice
    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    alice_polyvalent_key_fp = fopen( alice_polyvalent_key_str, "rb" );
    alice_polyvalent_proof_fp = fopen( alice_polyvalent_proof_str, "rb" );
    alice_monovalent_key_fp = fopen( alice_monovalent_key_str, "rb" );
    bob_monovalent_key_fp = fopen( bob_monovalent_key_str, "rb" );
    alice_shared_polyvalent_key_fp = fopen( alice_shared_polyvalent_key_str, "wb" );

    ret = xrn_exchange_polyvalent_key_wrapper( xrn_matrix_fp, alice_monovalent_key_fp,
                                               bob_monovalent_key_fp, alice_polyvalent_key_fp,
                                               alice_polyvalent_proof_fp, alice_shared_polyvalent_key_fp,
                                               settings );
    if ( ret != XSUCCESS ) {

        fclose( xrn_matrix_fp );
        fclose( alice_polyvalent_key_fp );
        fclose( alice_polyvalent_proof_fp );
        fclose( alice_monovalent_key_fp );
        fclose( bob_monovalent_key_fp );
        fclose( alice_shared_polyvalent_key_fp );

        remove( xrn_matrix_str );
        remove( alice_monovalent_key_str );
        remove( alice_polyvalent_key_str );
        remove( alice_polyvalent_proof_str );
        remove( bob_monovalent_key_str );
        remove( bob_polyvalent_key_str );
        remove( bob_polyvalent_proof_str );
        remove( alice_shared_polyvalent_key_str );
        remove( bob_shared_polyvalent_key_str );

        return 1;

    }

    fclose( xrn_matrix_fp );
    fclose( alice_polyvalent_key_fp );
    fclose( alice_polyvalent_proof_fp );
    fclose( alice_monovalent_key_fp );
    fclose( bob_monovalent_key_fp );
    fclose( alice_shared_polyvalent_key_fp );

    // key exchange bob

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    bob_polyvalent_key_fp = fopen( bob_polyvalent_key_str, "rb" );
    bob_polyvalent_proof_fp = fopen( bob_polyvalent_proof_str, "rb" );
    bob_monovalent_key_fp = fopen( bob_monovalent_key_str, "rb" );
    alice_monovalent_key_fp = fopen( alice_monovalent_key_str, "rb" );
    bob_shared_polyvalent_key_fp = fopen( bob_shared_polyvalent_key_str, "wb" );

    ret = xrn_exchange_polyvalent_key_wrapper( xrn_matrix_fp, bob_monovalent_key_fp,
                                               alice_monovalent_key_fp, bob_polyvalent_key_fp,
                                               bob_polyvalent_proof_fp, bob_shared_polyvalent_key_fp,
                                               settings );

    if ( ret != XSUCCESS ) {

        fclose( xrn_matrix_fp );
        fclose( bob_polyvalent_key_fp );
        fclose( bob_polyvalent_proof_fp );
        fclose( bob_monovalent_key_fp );
        fclose( alice_monovalent_key_fp );
        fclose( bob_shared_polyvalent_key_fp );

        remove( xrn_matrix_str );
        remove( alice_monovalent_key_str );
        remove( alice_polyvalent_key_str );
        remove( alice_polyvalent_proof_str );
        remove( bob_monovalent_key_str );
        remove( bob_polyvalent_key_str );
        remove( bob_polyvalent_proof_str );
        remove( alice_shared_polyvalent_key_str );
        remove( bob_shared_polyvalent_key_str );

        return 1;

    }

    fclose( xrn_matrix_fp );
    fclose( bob_polyvalent_key_fp );
    fclose( bob_polyvalent_proof_fp );
    fclose( bob_monovalent_key_fp );
    fclose( alice_monovalent_key_fp );
    fclose( bob_shared_polyvalent_key_fp );

    // load shared keys

    bob_shared_polyvalent_key_fp = fopen( bob_shared_polyvalent_key_str, "rb" );
    alice_shared_polyvalent_key_fp = fopen( alice_shared_polyvalent_key_str, "rb" );
    ret = xrn_load_polyvalent_key( &shared_alice, alice_shared_polyvalent_key_fp, &settings );

    if ( ret != XSUCCESS ) {

        fclose( bob_shared_polyvalent_key_fp );
        fclose( alice_shared_polyvalent_key_fp );

        remove( xrn_matrix_str );
        remove( alice_monovalent_key_str );
        remove( alice_polyvalent_key_str );
        remove( alice_polyvalent_proof_str );
        remove( bob_monovalent_key_str );
        remove( bob_polyvalent_key_str );
        remove( bob_polyvalent_proof_str );
        remove( alice_shared_polyvalent_key_str );
        remove( bob_shared_polyvalent_key_str );

        return 1;

    }

    ret = xrn_load_polyvalent_key( &shared_bob, bob_shared_polyvalent_key_fp, &settings );

    if ( ret != XSUCCESS ) {

        fclose( bob_shared_polyvalent_key_fp );
        fclose( alice_shared_polyvalent_key_fp );

        remove( xrn_matrix_str );
        remove( alice_monovalent_key_str );
        remove( alice_polyvalent_key_str );
        remove( alice_polyvalent_proof_str );
        remove( bob_monovalent_key_str );
        remove( bob_polyvalent_key_str );
        remove( bob_polyvalent_proof_str );
        remove( alice_shared_polyvalent_key_str );
        remove( bob_shared_polyvalent_key_str );

        return 1;

    }

    fclose( bob_shared_polyvalent_key_fp );
    fclose( alice_shared_polyvalent_key_fp );

    remove( xrn_matrix_str );
    remove( alice_monovalent_key_str );
    remove( alice_polyvalent_key_str );
    remove( alice_polyvalent_proof_str );
    remove( bob_monovalent_key_str );
    remove( bob_polyvalent_key_str );
    remove( bob_polyvalent_proof_str );
    remove( alice_shared_polyvalent_key_str );
    remove( bob_shared_polyvalent_key_str );

    for ( i = 0; i < XRN_STATE_KEY_SIZE; i++ ) {
        XNUM_CMP( shared_bob.state[i], shared_alice.state[i], error );
        if ( error == 1 ) {
            return 1;
        }

    }

    return 0;

}

int test_monovalent_key_verification(
 )
{

    FILE *xrn_matrix_fp;
    FILE *monovalent_key_fp;
    FILE *polyvalent_proof_fp;
    FILE *polyvalent_key_fp;
    char xrn_matrix_str[256];
    char monovalent_key_str[256];
    char polyvalent_proof_str[256];
    char polyvalent_key_str[256];
    xrn_crypto_extra_settings_t settings;
    uint64_t start_timestamp, end_timestamp;
    xmonovalent_key_t monovalent_key;
    int ret;

    xnum_t cob, cos;
    xgenesis_base_t *ob;
    xrn_matrix_t *xm;

    xrn_load_default_settings( &settings );
    settings.const_exec_time = ( uint8_t ) rand(  ) % 2;
    settings.thread_enable = ( uint8_t ) rand(  ) % 2;

    strcpy( xrn_matrix_str, "../cache/to_remove_load_monovalent_matrix.txt" );
    strcpy( monovalent_key_str, "../cache/to_remove_load_monovalent_monovalent.txt" );
    strcpy( polyvalent_proof_str, "../cache/to_remove_load_monovalent_polyproof.txt" );
    strcpy( polyvalent_key_str, "../cache/to_remove_load_monovalent_polykey.txt" );

    // generate xoron matrix
    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_init( ob );
    xrn_matrix_fp = fopen( xrn_matrix_str, "wb" );
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );
    xrn_dump_matrix( xm, xrn_matrix_fp, settings );
    free( xm );
    fclose( xrn_matrix_fp );

    // make time stamps

    time( ( time_t * ) & start_timestamp );
    end_timestamp = start_timestamp + 3000;

    // make monovalent key

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    polyvalent_key_fp = fopen( polyvalent_key_str, "wb" );
    polyvalent_proof_fp = fopen( polyvalent_proof_str, "wb" );
    monovalent_key_fp = fopen( monovalent_key_str, "wb" );

    ret =
        xrn_make_monovalent_key_wrapper( xrn_matrix_fp, start_timestamp, end_timestamp, polyvalent_key_fp,
                                         polyvalent_proof_fp, monovalent_key_fp, settings );

    if ( ret != XSUCCESS ) {

        fclose( xrn_matrix_fp );
        fclose( polyvalent_key_fp );
        fclose( polyvalent_proof_fp );
        fclose( monovalent_key_fp );
        remove( xrn_matrix_str );
        remove( polyvalent_key_str );
        remove( polyvalent_proof_str );
        remove( monovalent_key_str );
        return 1;

    }

    fclose( xrn_matrix_fp );
    fclose( polyvalent_key_fp );
    fclose( polyvalent_proof_fp );
    fclose( monovalent_key_fp );

    // make verification

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    polyvalent_proof_fp = fopen( polyvalent_proof_str, "rb" );
    monovalent_key_fp = fopen( monovalent_key_str, "rb" );

    ret = xrn_check_monovalent_key_wrapper( xrn_matrix_fp, monovalent_key_fp, polyvalent_proof_fp, settings );

    if ( ret != XSUCCESS ) {

        fclose( xrn_matrix_fp );
        fclose( polyvalent_proof_fp );
        fclose( monovalent_key_fp );
        remove( xrn_matrix_str );
        remove( polyvalent_key_str );
        remove( polyvalent_proof_str );
        remove( monovalent_key_str );
        return 1;

    }

    fclose( xrn_matrix_fp );
    fclose( polyvalent_proof_fp );
    fclose( monovalent_key_fp );

    // inject error

    monovalent_key_fp = fopen( monovalent_key_str, "rb" );

    ret = xrn_load_monovalent_key( &monovalent_key, monovalent_key_fp, &settings );
    if ( ret != XSUCCESS ) {

        fclose( monovalent_key_fp );
        remove( xrn_matrix_str );
        remove( polyvalent_key_str );
        remove( polyvalent_proof_str );
        remove( monovalent_key_str );
        return 1;

    }

    fclose( monovalent_key_fp );

    monovalent_key.state[rand(  ) % XRN_STATE_KEY_SIZE].xnum[rand(  ) % XNBITS_NUM] =
        monovalent_key.state[rand(  ) % XRN_STATE_KEY_SIZE].xnum[rand(  ) %
                                                                 XNBITS_NUM] ^ ( ( XINT_TYPE ) rand(  ) );

    monovalent_key_fp = fopen( monovalent_key_str, "wb" );

    ret = xrn_dump_monovalent_key( monovalent_key, monovalent_key_fp, settings );

    if ( ret != XSUCCESS ) {

        fclose( monovalent_key_fp );
        remove( xrn_matrix_str );
        remove( polyvalent_key_str );
        remove( polyvalent_proof_str );
        remove( monovalent_key_str );
        return 1;

    }

    fclose( monovalent_key_fp );

    // check monovalent key and expect failure

    xrn_matrix_fp = fopen( xrn_matrix_str, "rb" );
    polyvalent_proof_fp = fopen( polyvalent_proof_str, "rb" );
    monovalent_key_fp = fopen( monovalent_key_str, "rb" );

    ret = xrn_check_monovalent_key_wrapper( xrn_matrix_fp, monovalent_key_fp, polyvalent_proof_fp, settings );

    if ( ret == XSUCCESS ) {

        fclose( xrn_matrix_fp );
        fclose( polyvalent_proof_fp );
        fclose( monovalent_key_fp );
        remove( xrn_matrix_str );
        remove( polyvalent_key_str );
        remove( polyvalent_proof_str );
        remove( monovalent_key_str );
        return 1;

    }

    fclose( xrn_matrix_fp );
    fclose( polyvalent_proof_fp );
    fclose( monovalent_key_fp );

    remove( xrn_matrix_str );
    remove( polyvalent_key_str );
    remove( polyvalent_proof_str );
    remove( monovalent_key_str );

    return 0;

}

int test_make_steg_raw(
 )
{

#define XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG (256 * 4 * 256)

    FILE *fpi, *fpe;
    FILE *fpb1, *fps;
    uint8_t encoded_bytes[XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG];
    uint8_t envelop_bytes[XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG];
    uint8_t out_envelop_bytes[XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG];
    uint8_t out_block_bytes[XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG];
    uint64_t block_length;
    uint64_t encoded_bytes_length;
    uint64_t envelop_bytes_length;
    int i;
    char fpi_str[256];
    char fpb1_str[256];
    char fpe_str[256];
    char fps_str[256];
    int error, cnt0, cnt1;
    char ch1, ch2, ch3;
    uint8_t u8;

    strcpy( fpi_str, "../cache/to_remove_test_make_steg_raw_input.txt" );
    strcpy( fpb1_str, "../cache/to_remove_test_make_steg_raw_exctracted_block.txt" );
    strcpy( fpe_str, "../cache/to_remove_test_make_envelop_raw.txt" );
    strcpy( fps_str, "../cache/to_remove_test_steganography_raw.txt" );

    encoded_bytes_length = XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG;
    envelop_bytes_length = XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG;

    // create input file

    fpi = fopen( fpi_str, "wb" );
    for ( i = 0; i < XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG; i++ ) {
        u8 = ( uint8_t ) rand(  ) % 256;
        encoded_bytes[i] = u8;

        // write the file
        if ( fwrite( &u8, 1, 1, fpi ) != 1 ) {
            fclose( fpi );
            remove( fpi_str );
            return 1;
        }

    }

    fclose( fpi );

    // create envelop

    fpe = fopen( fpe_str, "wb" );

    for ( i = 0; i < XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG; i++ ) {
        u8 = ( uint8_t ) rand(  ) % 256;
        envelop_bytes[i] = u8;
        // write the file
        if ( fwrite( &u8, 1, 1, fpe ) != 1 ) {
            fclose( fpe );
            remove( fpi_str );
            remove( fpe_str );
            return 1;
        }

    }

    fclose( fpe );

    // create one steganography block

    fpi = fopen( fpi_str, "rb" );
    fpe = fopen( fpe_str, "rb" );
    fps = fopen( fps_str, "wb" );

    if ( XSUCCESS != xrn_make_steg_raw( fpi, fpe, fps ) ) {
        fclose( fpi );
        fclose( fps );
        fclose( fpe );
        remove( fpi_str );
        remove( fpe_str );
        remove( fps_str );
        return 1;
    }

    fclose( fpi );
    fclose( fps );
    fclose( fpe );

    if ( XSUCCESS !=
         xrn_make_steg_raw_bytes( encoded_bytes, encoded_bytes_length, envelop_bytes, envelop_bytes_length,
                                  out_envelop_bytes, envelop_bytes_length ) ) {
        remove( fpi_str );
        remove( fpe_str );
        remove( fps_str );
        return 1;
    }

    // exctract block from steganography file

    fps = fopen( fps_str, "rb" );
    fpb1 = fopen( fpb1_str, "wb" );

    if ( XSUCCESS != xrn_extract_steg_raw( fps, fpb1 ) ) {
        fclose( fpb1 );
        fclose( fps );
        remove( fpi_str );
        remove( fpe_str );
        remove( fpb1_str );
        remove( fps_str );
        return 1;
    }

    fclose( fps );
    fclose( fpb1 );

    if ( XSUCCESS != xrn_extract_steg_raw_bytes( out_envelop_bytes, envelop_bytes_length, out_block_bytes,
                                                 envelop_bytes_length, &block_length ) ) {
        remove( fpi_str );
        remove( fpe_str );
        remove( fpb1_str );
        remove( fps_str );
        return 1;
    }

    // compare the two blocks

    fpb1 = fopen( fpb1_str, "rb" );
    error = 0;
    i = 0;
    ch3 = 0;

    for ( i = 0; i < 288 * 2 + 5; i++ ) {

        ch3 = ( char ) out_block_bytes[i];

        // Input character from both files
        cnt1 = ( int ) fread( &ch2, sizeof( uint8_t ), 1, fpb1 );
        error = ( ( ch2 != ch3 ) || ( cnt1 != 1 ) ) || error;

    }

    fclose( fpb1 );

    remove( fpi_str );
    remove( fpe_str );
    remove( fpb1_str );
    remove( fps_str );

    return error;

}

int test_make_steg_block(
 )
{

#define XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG (256 * 4 * 256)

    FILE *fpi, *fpe;
    FILE *fpb0, *fpb1, *fps;
    uint8_t folding_en;
    uint8_t encoded_bytes[XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG];
    uint8_t envelop_bytes[XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG];
    uint8_t out_envelop_bytes[XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG];
    uint8_t out_block_bytes[XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG];
    uint64_t block_length;
    uint64_t encoded_bytes_length;
    uint64_t envelop_bytes_length;
    int i;
    uint32_t tag;
    uint64_t offset;
    uint64_t capacity, capacity2;
    xrn_crypto_extra_settings_t settings;
    char fpi_str[256];
    char fpb0_str[256];
    char fpb1_str[256];
    char fpe_str[256];
    char fps_str[256];
    int error, cnt0, cnt1;
    char ch1, ch2, ch3;
    uint8_t u8;

    strcpy( fpi_str, "../cache/to_remove_test_make_steg_input.txt" );
    strcpy( fpb0_str, "../cache/to_remove_test_make_steg_classical_block.txt" );
    strcpy( fpb1_str, "../cache/to_remove_test_make_steg_exctracted_block.txt" );
    strcpy( fpe_str, "../cache/to_remove_test_make_envelop.txt" );
    strcpy( fps_str, "../cache/to_remove_test_steganography.txt" );

    xrn_load_default_settings( &settings );
    tag = ( uint32_t ) rand(  );

    encoded_bytes_length = XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG;
    envelop_bytes_length = XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG;

    folding_en = ( uint8_t ) rand(  ) % 2;

    // create input file

    fpi = fopen( fpi_str, "wb" );

    for ( i = 0; i < XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG; i++ ) {
        u8 = ( uint8_t ) rand(  ) % 256;
        encoded_bytes[i] = u8;

        // write the file
        if ( fwrite( &u8, 1, 1, fpi ) != 1 ) {
            fclose( fpi );
            remove( fpi_str );
            return 1;
        }

    }

    fclose( fpi );

    // create envelop

    fpe = fopen( fpe_str, "wb" );

    for ( i = 0; i < XRN_TEST_CRYPTO_ENCODED_ENVELOP_BYTES_BIG; i++ ) {
        u8 = ( uint8_t ) rand(  ) % 256;
        envelop_bytes[i] = u8;
        // write the file
        if ( fwrite( &u8, 1, 1, fpe ) != 1 ) {
            fclose( fpe );
            remove( fpi_str );
            remove( fpe_str );
            return 1;
        }

    }

    fclose( fpe );

    // get capacity

    fpe = fopen( fpe_str, "rb" );
    xrn_estimate_steg_block_length( fpe, folding_en, &capacity );
    fclose( fpe );

    xrn_estimate_steg_block_length_bytes( envelop_bytes_length, folding_en, &capacity2 );
    if ( capacity != capacity2 ) {
        remove( fpi_str );
        remove( fpe_str );
        remove( fpb0_str );
        return 1;
    }

    // create one classical block

    fpi = fopen( fpi_str, "rb" );
    fpb0 = fopen( fpb0_str, "wb" );

    offset = ( uint64_t ) ( rand(  ) % ( int ) capacity );
    if ( XSUCCESS != xrn_make_block( fpi, fpb0, tag, 0, offset ) ) {
        fclose( fpi );
        fclose( fpb0 );
        remove( fpi_str );
        remove( fpe_str );
        remove( fpb0_str );
        return 1;
    }

    fclose( fpi );
    fclose( fpb0 );

    // create one steganography block

    fpi = fopen( fpi_str, "rb" );
    fpe = fopen( fpe_str, "rb" );
    fps = fopen( fps_str, "wb" );

    if ( XSUCCESS != xrn_make_steg_block( fpi, fpe, fps, folding_en, tag, 0, offset, settings ) ) {
        fclose( fpi );
        fclose( fps );
        fclose( fpe );
        remove( fpi_str );
        remove( fpe_str );
        remove( fpb0_str );
        remove( fps_str );
        return 1;
    }

    fclose( fpi );
    fclose( fps );
    fclose( fpe );

    if ( XSUCCESS !=
         xrn_make_steg_block_bytes( encoded_bytes, encoded_bytes_length, envelop_bytes, envelop_bytes_length,
                                    out_envelop_bytes, envelop_bytes_length, folding_en, tag, 0, offset,
                                    settings ) ) {
        remove( fpi_str );
        remove( fpe_str );
        remove( fpb0_str );
        remove( fps_str );
        return 1;
    }

    // exctract block from steganography file

    fps = fopen( fps_str, "rb" );
    fpb1 = fopen( fpb1_str, "wb" );

    if ( XSUCCESS != xrn_extract_steg_block( fps, fpb1, settings ) ) {
        fclose( fpb1 );
        fclose( fps );
        remove( fpi_str );
        remove( fpe_str );
        remove( fpb0_str );
        remove( fpb1_str );
        remove( fps_str );
        return 1;
    }

    fclose( fps );
    fclose( fpb1 );

    if ( XSUCCESS != xrn_extract_steg_block_bytes( out_envelop_bytes, envelop_bytes_length, out_block_bytes,
                                                   envelop_bytes_length, &block_length, settings ) ) {
        remove( fpi_str );
        remove( fpe_str );
        remove( fpb0_str );
        remove( fpb1_str );
        remove( fps_str );
        return 1;
    }

    // compare the two blocks

    fpb0 = fopen( fpb0_str, "rb" );
    fpb1 = fopen( fpb1_str, "rb" );
    error = 0;
    i = 0;
    ch3 = 0;

    do {
        if ( i < block_length ) {
            ch3 = ( char ) out_block_bytes[i];
        }

        // Input character from both files
        cnt0 = ( int ) fread( &ch1, sizeof( uint8_t ), 1, fpb0 );
        cnt1 = ( int ) fread( &ch2, sizeof( uint8_t ), 1, fpb1 );
        error = ( ( ch1 != ch2 ) || ( cnt0 != cnt1 ) ) || error;

        if ( ( i < block_length ) && ( error == 0 ) ) {
            error = ( ch1 != ch3 ) || error;
        }

        i++;

    } while ( cnt0 != 0 && cnt1 != 0 );

    fclose( fpb0 );
    fclose( fpb1 );

    remove( fpi_str );
    remove( fpe_str );
    remove( fpb0_str );
    remove( fpb1_str );
    remove( fps_str );

    if ( i != block_length + 1 ) {
        error = 1;
    }

    return error;

}

int test_make_steg_block_small_envelop(
 )
{

#define XRN_TEST_CRYPTO_ENVELOP_BYTES_SMALL (256 * 10)
#define XRN_TEST_CRYPTO_ENCODED_BYTES_SMALL (256 * 4 * 256)

    FILE *fpi, *fpe;
    FILE *fpb0, *fpb1, *fps;
    uint8_t folding_en;
    int i;
    uint32_t tag;
    uint64_t offset;
    uint64_t capacity, capacity2;
    xrn_crypto_extra_settings_t settings;
    char fpi_str[256];
    char fpb0_str[256];
    char fpb1_str[256];
    char fpe_str[256];
    char fps_str[256];
    int error, cnt0, cnt1;
    char ch1;
    char ch2;
    char ch3;
    uint8_t envelop_bytes[XRN_TEST_CRYPTO_ENVELOP_BYTES_SMALL];
    uint8_t out_envelop_bytes[XRN_TEST_CRYPTO_ENVELOP_BYTES_SMALL];
    uint8_t out_block_bytes[XRN_TEST_CRYPTO_ENVELOP_BYTES_SMALL];
    uint8_t encoded_bytes[XRN_TEST_CRYPTO_ENCODED_BYTES_SMALL];
    uint64_t encoded_bytes_length;
    uint64_t envelop_bytes_length;
    uint64_t block_length;
    uint8_t u8;

    strcpy( fpi_str, "../cache/to_remove_test_make_steg_input.txt" );
    strcpy( fpb0_str, "../cache/to_remove_test_make_steg_classical_block.txt" );
    strcpy( fpb1_str, "../cache/to_remove_test_make_steg_exctracted_block.txt" );
    strcpy( fpe_str, "../cache/to_remove_test_make_envelop.txt" );
    strcpy( fps_str, "../cache/to_remove_test_steganography.txt" );

    xrn_load_default_settings( &settings );
    tag = ( uint32_t ) rand(  );
    encoded_bytes_length = XRN_TEST_CRYPTO_ENCODED_BYTES_SMALL;
    envelop_bytes_length = XRN_TEST_CRYPTO_ENVELOP_BYTES_SMALL;
    folding_en = ( uint8_t ) rand(  ) % 2;

    // create input file

    fpi = fopen( fpi_str, "wb" );

    for ( i = 0; i < XRN_TEST_CRYPTO_ENCODED_BYTES_SMALL; i++ ) {
        u8 = ( uint8_t ) rand(  ) % 256;
        encoded_bytes[i] = u8;

        // write the file
        if ( fwrite( &u8, 1, 1, fpi ) != 1 ) {

            fclose( fpi );
            remove( fpi_str );
            return 1;
        }

    }

    fclose( fpi );

    // create envelop

    fpe = fopen( fpe_str, "wb" );
    for ( i = 0; i < XRN_TEST_CRYPTO_ENVELOP_BYTES_SMALL; i++ ) {
        u8 = ( uint8_t ) rand(  ) % 256;
        envelop_bytes[i] = u8;

        // write the file
        if ( fwrite( &u8, 1, 1, fpe ) != 1 ) {

            fclose( fpe );
            remove( fpi_str );
            remove( fpe_str );
            return 1;
        }

    }

    fclose( fpe );

    // get capacity

    fpe = fopen( fpe_str, "rb" );
    xrn_estimate_steg_block_length( fpe, folding_en, &capacity );
    fclose( fpe );

    xrn_estimate_steg_block_length_bytes( envelop_bytes_length, folding_en, &capacity2 );
    if ( capacity != capacity2 ) {

        remove( fpi_str );
        remove( fpe_str );
        remove( fpb0_str );
        return 1;
    }

    // create one classical block

    fpi = fopen( fpi_str, "rb" );
    fpb0 = fopen( fpb0_str, "wb" );

    offset = 0;
    while ( offset < 2 ) {
        offset = ( uint64_t ) ( rand(  ) % ( int ) capacity );
    }

    if ( XSUCCESS != xrn_make_block( fpi, fpb0, tag, 0, offset ) ) {

        fclose( fpi );
        fclose( fpb0 );
        remove( fpi_str );
        remove( fpe_str );
        remove( fpb0_str );
        return 1;
    }

    fclose( fpi );
    fclose( fpb0 );

    // create one steganography block

    fpi = fopen( fpi_str, "rb" );
    fpe = fopen( fpe_str, "rb" );
    fps = fopen( fps_str, "wb" );

    if ( XSUCCESS != xrn_make_steg_block( fpi, fpe, fps, folding_en, tag, 0, offset, settings ) ) {

        fclose( fpi );
        fclose( fps );
        fclose( fpe );
        remove( fpi_str );
        remove( fpe_str );
        remove( fpb0_str );
        remove( fps_str );
        return 1;
    }

    fclose( fpi );
    fclose( fps );
    fclose( fpe );

    if ( XSUCCESS !=
         xrn_make_steg_block_bytes( encoded_bytes, encoded_bytes_length, envelop_bytes, envelop_bytes_length,
                                    out_envelop_bytes, envelop_bytes_length, folding_en, tag, 0, offset,
                                    settings ) ) {

        remove( fpi_str );
        remove( fpe_str );
        remove( fpb0_str );
        remove( fps_str );
        return 1;
    }

    // exctract block from steganography file

    fps = fopen( fps_str, "rb" );
    fpb1 = fopen( fpb1_str, "wb" );

    if ( XSUCCESS != xrn_extract_steg_block( fps, fpb1, settings ) ) {

        fclose( fpb1 );
        fclose( fps );
        remove( fpi_str );
        remove( fpe_str );
        remove( fpb0_str );
        remove( fpb1_str );
        remove( fps_str );
        return 1;
    }

    fclose( fps );
    fclose( fpb1 );

    if ( XSUCCESS != xrn_extract_steg_block_bytes( out_envelop_bytes, envelop_bytes_length, out_block_bytes,
                                                   envelop_bytes_length, &block_length, settings ) ) {

        remove( fpi_str );
        remove( fpe_str );
        remove( fpb0_str );
        remove( fpb1_str );
        remove( fps_str );
        return 1;
    }

    // compare the two blocks

    fpb0 = fopen( fpb0_str, "rb" );
    fpb1 = fopen( fpb1_str, "rb" );
    error = 0;
    i = 0;
    ch3 = 0;

    do {
        if ( i < block_length ) {
            ch3 = ( char ) out_block_bytes[i];
        }

        // Input character from both files
        cnt0 = ( int ) fread( &ch1, sizeof( uint8_t ), 1, fpb0 );
        cnt1 = ( int ) fread( &ch2, sizeof( uint8_t ), 1, fpb1 );

        error = ( ( ch1 != ch2 ) || ( cnt0 != cnt1 ) ) || error;
        if ( ( i < block_length ) && ( error == 0 ) ) {
            error = ( ch1 != ch3 ) || error;

        }

        i++;

    } while ( cnt0 != 0 && cnt1 != 0 );

    fclose( fpb0 );
    fclose( fpb1 );

    remove( fpi_str );
    remove( fpe_str );
    remove( fpb0_str );
    remove( fpb1_str );
    remove( fps_str );

    if ( i != block_length + 1 ) {

        error = 1;
    }

    return error;

}

int xrn_ring_sig_test(
 )
{

    //   int error , cnt0 , cnt1;
    xgenesis_base_t *ob;
    xrn_matrix_t *xm;
    xnum_t cob, cos;
    int i, ndecoys, crc_bytes;
    xstart_point_t start;
    xbinomial_key_t binomial_A, binomial_x, binomial_B, *ring;
    xmonomial_key_t monomial_A, monomial_B;
    xring_signature_t xring;
    xring_signature_t xring2;
    xring_signature_t xring2_perm;
    uint8_t c;

    char fname_input_file[256];
    FILE *fpi;
    xrn_crypto_extra_settings_t settings;

    strcpy( settings.rnd_str, "" );
    settings.thread_enable = ( uint8_t ) ( rand(  ) ) % 2;
    settings.const_exec_time = ( uint8_t ) ( rand(  ) ) % 2;

    crc_bytes = rand(  ) % 9;
    while ( ( ( crc_bytes < 8 ) && ( crc_bytes >= 5 ) ) || ( crc_bytes == 0 ) || ( crc_bytes == 3 ) ) {
        crc_bytes = rand(  ) % 9;
    }

    settings.crc_bytes = ( uint8_t ) ( crc_bytes );

    xrn_initialize_encoding_settings( &settings.encoding_settings.i_settings );
    xrn_initialize_encoding_settings( &settings.encoding_settings.o_settings );
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;

    settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    while ( settings.state_size < 2 ) {
        settings.state_size = ( uint8_t ) ( rand(  ) ) % ( XRN_MAX_STATE_SIZE + 1 );
    }

    if ( IMPOSE_MAX_STATE_SIZE ) {
        settings.state_size = XRN_MAX_STATE_SIZE;
    }

    strcpy( fname_input_file, "../cache/to_remove_block_ringsig_all_file.txt" );

    // generate origin base

    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    fpi = fopen( fname_input_file, "wb" );
    for ( i = 0; i < 336; i++ ) {
        c = ( uint8_t ) ( rand(  ) % 256 );
        fwrite( &c, sizeof( char ), 1, fpi );
    }

    fclose( fpi );

    // generate xoron matrix

    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign
    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );

    // generate bob monomial and binomial key

    xrn_make_start_point( &start, xm, settings );

    xrn_make_monomial_key( &monomial_A, settings );
    xrn_make_monomial_key( &monomial_B, settings );
    xrn_make_binomial_key( xm, start, monomial_A, &binomial_A, settings );
    xrn_make_binomial_key( xm, start, monomial_B, &binomial_B, settings );

    // generate binomial keys
    ndecoys = 5;

    ring = ( xbinomial_key_t * ) malloc( ( uint64_t ) ( ndecoys ) * ( uint64_t ) sizeof( xbinomial_key_t ) );

    // perform ring signature

    for ( i = 0; i < ndecoys; i++ ) {
        xrn_initialize_rnd_num( &ring[i].end );
        ring[i].start = start.start;
    }

    fpi = fopen( fname_input_file, "rb" );

    if ( XSUCCESS !=
         xrn_make_ring_signature( fpi, ring, monomial_A, binomial_A, binomial_B, xm, ( uint16_t ) ndecoys,
                                  &xring, settings ) ) {

        fclose( fpi );
        remove( fname_input_file );
        free( ring );
        free( xm );
        return 1;

    }

    fclose( fpi );

    // check ring signature

    fpi = fopen( fname_input_file, "rb" );

    if ( XSUCCESS != xrn_check_ring_signature( fpi, xring, monomial_B, xm, &binomial_x, settings ) ) {

        fclose( fpi );
        free( xm );
        free( ring );
        remove( fname_input_file );
        return 1;

    }

    fclose( fpi );

    // make second ring signature

    fpi = fopen( fname_input_file, "rb" );

    for ( i = 0; i < ndecoys; i++ ) {
        xrn_initialize_rnd_num( &ring[i].end );
        ring[i].start = start.start;
    }

    if ( XSUCCESS !=
         xrn_make_ring_signature( fpi, ring, monomial_A, binomial_A, binomial_B, xm, ( uint16_t ) ndecoys,
                                  &xring2, settings ) ) {

        fclose( fpi );
        remove( fname_input_file );
        free( ring );
        free( xm );
        return 1;

    }

    fclose( fpi );

    if ( XSUCCESS != xrn_permute_ring_signature( binomial_A,
                                                 binomial_B, xring, xring2, &xring2_perm, settings ) ) {

        remove( fname_input_file );
        free( ring );
        free( xm );
        return 1;
    }

    // check ring signature

    fpi = fopen( fname_input_file, "rb" );

    if ( XSUCCESS != xrn_check_ring_signature( fpi, xring2_perm, monomial_B, xm, &binomial_x, settings ) ) {

        fclose( fpi );
        free( xm );
        free( ring );
        remove( fname_input_file );
        return 1;

    }

    fclose( fpi );

    free( xm );
    free( ring );
    remove( fname_input_file );

    return 0;

}

int test_crypto_all( FILE * fp, int runs, int non_block
 )
{

    time_t t;
    int error;
    int occ;
    char buff[256];

    int v_test_verify_certificate_proof;
    int v_test_verify_signature_proof;
    int v_test_verify_signature_bytes_proof;
    int v_negative_test_signature_asym;
    int v_test_xrn_sign_asy_bytes;
    int v_negative_test_xrn_sign_asy_bytes;
    int v_negative_test_xrn_make_certificate_asymmetric_wrapper_time;
    int v_test_signature_sym;
    int v_negative_test_signature_sym;
    int v_test_xrn_sign_sym_bytes;
    int v_negative_test_xrn_sign_sym_bytes;
    int v_test_xrn_make_certificate_symmetric_wrapper;
    int v_negative_test_xrn_make_certificate_symmetric_wrapper_time;
    int v_xrn_ring_sig_test;
    int v_xrn_ring_sig_test_bytes;
    int v_test_encrypt_symmetric_crc;
    int v_test_hash_str_file;
    int v_test_key_exchange_wrapper;
    int v_test_encrypt_symmetric;
    int v_test_encrypt_asymmetric;
    int v_test_encrypt_asymmetric_bytes;
    int v_test_xrn_generate_confidential_pseudo_random_number_wrapper;
    int v_test_encrypt_split_join;
    int v_test_encrypt_split_join_bytes;
    int v_test_encrypt_symmetric_all_file_crc;
    int v_test_encrypt_symmetric_bytes;
    int v_test_loop_enc_stream;
    int v_test_verify_binomial_proof;
    int v_negative_test_verify_signature_bytes_proof;
    int v_test_signature_asym;
    int v_test_xrn_make_certificate_asymmetric_wrapper;
    int v_test_matrix_compressed_deterministic_permute;
    int v_test_matrix_compressed_key_permute;
    int v_test_hash_cmp;
    int v_test_encoder;
    int v_test_encoder_bytes;
    int v_test_xrn_exchange_polyvalent_key;
    int v_test_monovalent_key_verification;
    int v_test_make_steg_block;
    int v_test_make_steg_block_small_envelop;
    int v_test_make_steg_raw;

    error = 0;

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_make_steg_raw = test_make_steg_raw(  );
        error += v_test_make_steg_raw;
        printf( "[%4d]", occ );
        if ( !v_test_make_steg_raw ) {
            printf( "test_crypto_lib -> test_make_steg_raw passed\n" );
            fprintf( fp, "test_crypto_lib -> test_make_steg_raw passed\n" );
        } else {
            printf( "test_crypto_lib -> test_make_steg_raw failed\n" );
            fprintf( fp, "test_crypto_lib -> test_make_steg_raw failed\n" );
        }

        if ( v_test_make_steg_raw != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_xrn_ring_sig_test = xrn_ring_sig_test(  );
        error += v_xrn_ring_sig_test;
        printf( "[%4d]", occ );
        if ( !v_xrn_ring_sig_test ) {
            printf( "test_crypto_lib -> xrn_ring_sig_test passed\n" );
            fprintf( fp, "test_crypto_lib -> xrn_ring_sig_test passed\n" );
        } else {
            printf( "test_crypto_lib -> xrn_ring_sig_test failed\n" );
            fprintf( fp, "test_crypto_lib -> xrn_ring_sig_test failed\n" );
        }

        if ( v_xrn_ring_sig_test != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_verify_certificate_proof = test_verify_certificate_proof(  );
        error += v_test_verify_certificate_proof;
        printf( "[%4d]", occ );
        if ( !v_test_verify_certificate_proof ) {
            printf( "test_crypto_lib -> test_verify_certificate_proof passed\n" );
            fprintf( fp, "test_crypto_lib -> test_verify_certificate_proof passed\n" );
        } else {
            printf( "test_crypto_lib -> test_verify_certificate_proof failed\n" );
            fprintf( fp, "test_crypto_lib -> test_verify_certificate_proof failed\n" );
        }

        if ( v_test_verify_certificate_proof != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_negative_test_xrn_make_certificate_asymmetric_wrapper_time =
            negative_test_xrn_make_certificate_asymmetric_wrapper_time(  );
        error += v_negative_test_xrn_make_certificate_asymmetric_wrapper_time;
        printf( "[%4d]", occ );
        if ( !v_negative_test_xrn_make_certificate_asymmetric_wrapper_time ) {
            printf
                ( "test_crypto_lib -> negative_test_xrn_make_certificate_asymmetric_wrapper_time passed\n" );
            fprintf( fp,
                     "test_crypto_lib -> negative_test_xrn_make_certificate_asymmetric_wrapper_time passed\n" );
        } else {
            printf
                ( "test_crypto_lib -> negative_test_xrn_make_certificate_asymmetric_wrapper_time failed\n" );
            fprintf( fp,
                     "test_crypto_lib -> negative_test_xrn_make_certificate_asymmetric_wrapper_time failed\n" );
        }

        if ( v_negative_test_xrn_make_certificate_asymmetric_wrapper_time != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_xrn_make_certificate_symmetric_wrapper = test_xrn_make_certificate_symmetric_wrapper(  );
        error += v_test_xrn_make_certificate_symmetric_wrapper;
        printf( "[%4d]", occ );
        if ( !v_test_xrn_make_certificate_symmetric_wrapper ) {
            printf( "test_crypto_lib -> test_xrn_make_certificate_symmetric_wrapper passed\n" );
            fprintf( fp, "test_crypto_lib -> test_xrn_make_certificate_symmetric_wrapper passed\n" );
        } else {
            printf( "test_crypto_lib -> test_xrn_make_certificate_symmetric_wrapper failed\n" );
            fprintf( fp, "test_crypto_lib -> test_xrn_make_certificate_symmetric_wrapper failed\n" );
        }

        if ( v_test_xrn_make_certificate_symmetric_wrapper != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_negative_test_xrn_make_certificate_symmetric_wrapper_time =
            negative_test_xrn_make_certificate_symmetric_wrapper_time(  );
        error += v_negative_test_xrn_make_certificate_symmetric_wrapper_time;
        printf( "[%4d]", occ );
        if ( !v_negative_test_xrn_make_certificate_symmetric_wrapper_time ) {
            printf( "test_crypto_lib -> negative_test_xrn_make_certificate_symmetric_wrapper_time passed\n" );
            fprintf( fp,
                     "test_crypto_lib -> negative_test_xrn_make_certificate_symmetric_wrapper_time passed\n" );
        } else {
            printf( "test_crypto_lib -> negative_test_xrn_make_certificate_symmetric_wrapper_time failed\n" );
            fprintf( fp,
                     "test_crypto_lib -> negative_test_xrn_make_certificate_symmetric_wrapper_time failed\n" );
        }

        if ( v_negative_test_xrn_make_certificate_symmetric_wrapper_time != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_xrn_make_certificate_asymmetric_wrapper = test_xrn_make_certificate_asymmetric_wrapper(  );
        error += v_test_xrn_make_certificate_asymmetric_wrapper;
        printf( "[%4d]", occ );
        if ( !v_test_xrn_make_certificate_asymmetric_wrapper ) {
            printf( "test_crypto_lib -> test_xrn_make_certificate_asymmetric_wrapper passed\n" );
            fprintf( fp, "test_crypto_lib -> test_xrn_make_certificate_asymmetric_wrapper passed\n" );
        } else {
            printf( "test_crypto_lib -> test_xrn_make_certificate_asymmetric_wrapper failed\n" );
            fprintf( fp, "test_crypto_lib -> test_xrn_make_certificate_asymmetric_wrapper failed\n" );
        }

        if ( v_test_xrn_make_certificate_asymmetric_wrapper != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_encrypt_split_join = test_encrypt_split_join(  );
        error += v_test_encrypt_split_join;
        printf( "[%4d]", occ );
        if ( !v_test_encrypt_split_join ) {
            printf( "test_crypto_lib -> test_encrypt_split_join passed\n" );
            fprintf( fp, "test_crypto_lib -> test_encrypt_split_join passed\n" );
        } else {
            printf( "test_crypto_lib -> test_encrypt_split_join failed\n" );
            fprintf( fp, "test_crypto_lib -> test_encrypt_split_join failed\n" );
        }

        if ( v_test_encrypt_split_join != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_encrypt_split_join_bytes = test_encrypt_split_join_bytes(  );
        error += v_test_encrypt_split_join_bytes;
        printf( "[%4d]", occ );
        if ( !v_test_encrypt_split_join_bytes ) {
            printf( "test_crypto_lib -> test_encrypt_split_join_bytes passed\n" );
        } else {
            printf( "test_crypto_lib -> test_encrypt_split_join_bytes failed\n" );
        }

        if ( v_test_encrypt_split_join_bytes != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_make_steg_block_small_envelop = test_make_steg_block_small_envelop(  );
        error += v_test_make_steg_block_small_envelop;
        printf( "[%4d]", occ );
        if ( !v_test_make_steg_block_small_envelop ) {
            printf( "test_crypto_lib -> test_make_steg_block_small_envelop passed\n" );
            fprintf( fp, "test_crypto_lib -> test_make_steg_block_small_envelop passed\n" );
        } else {
            printf( "test_crypto_lib -> test_make_steg_block_small_envelop failed\n" );
            fprintf( fp, "test_crypto_lib -> test_make_steg_block_small_envelop failed\n" );
        }

        if ( v_test_make_steg_block_small_envelop != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_make_steg_block = test_make_steg_block(  );
        error += v_test_make_steg_block;
        printf( "[%4d]", occ );
        if ( !v_test_make_steg_block ) {
            printf( "test_crypto_lib -> test_make_steg_block passed\n" );
            fprintf( fp, "test_crypto_lib -> test_make_steg_block passed\n" );
        } else {
            printf( "test_crypto_lib -> test_make_steg_block failed\n" );
            fprintf( fp, "test_crypto_lib -> test_make_steg_block failed\n" );
        }

        if ( v_test_make_steg_block != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_hash_cmp = test_hash_cmp(  );
        error += v_test_hash_cmp;
        printf( "[%4d]", occ );
        if ( !v_test_hash_cmp ) {
            printf( "test_crypto_lib -> test_hash_cmp passed\n" );
            fprintf( fp, "test_crypto_lib -> test_hash_cmp passed\n" );
        } else {
            printf( "test_crypto_lib -> test_hash_cmp failed\n" );
            fprintf( fp, "test_crypto_lib -> test_hash_cmp failed\n" );
        }

        if ( v_test_hash_cmp != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_verify_binomial_proof = test_verify_binomial_proof(  );
        error += v_test_verify_binomial_proof;
        printf( "[%4d]", occ );
        if ( !v_test_verify_binomial_proof ) {
            printf( "test_crypto_lib -> test_verify_binomial_proof passed\n" );
            fprintf( fp, "test_crypto_lib -> test_verify_binomial_proof passed\n" );
        } else {
            printf( "test_crypto_lib -> test_verify_binomial_proof failed\n" );
            fprintf( fp, "test_crypto_lib -> test_verify_binomial_proof failed\n" );
        }

        if ( v_test_verify_binomial_proof != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_xrn_sign_sym_bytes = test_xrn_sign_sym_bytes(  );
        error += v_test_xrn_sign_sym_bytes;
        printf( "[%4d]", occ );
        if ( !v_test_xrn_sign_sym_bytes ) {
            printf( "test_crypto_lib -> test_xrn_sign_sym_bytes passed\n" );
            fprintf( fp, "test_crypto_lib -> test_xrn_sign_sym_bytes passed\n" );
        } else {
            printf( "test_crypto_lib -> test_xrn_sign_sym_bytes failed\n" );
            fprintf( fp, "test_crypto_lib -> test_xrn_sign_sym_bytes failed\n" );
        }

        if ( v_test_xrn_sign_sym_bytes != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {

        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_encrypt_symmetric_all_file_crc = test_encrypt_symmetric_all_file_crc(  );
        error += v_test_encrypt_symmetric_all_file_crc;
        printf( "[%4d]", occ );
        if ( !v_test_encrypt_symmetric_all_file_crc ) {
            printf( "test_crypto_lib -> negative test_encrypt_symmetric_all_file_crc passed\n" );
            fprintf( fp, "test_crypto_lib -> negative test_encrypt_symmetric_all_file_crc passed\n" );
        } else {
            printf( "test_crypto_lib -> negative test_encrypt_symmetric_all_file_crc failed\n" );
            fprintf( fp, "test_crypto_lib -> negative test_encrypt_symmetric_all_file_crc failed\n" );
        }

        if ( v_test_encrypt_symmetric_all_file_crc != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_xrn_generate_confidential_pseudo_random_number_wrapper =
            test_xrn_generate_confidential_pseudo_random_number_wrapper(  );
        error += v_test_xrn_generate_confidential_pseudo_random_number_wrapper;
        printf( "[%4d]", occ );
        if ( !v_test_xrn_generate_confidential_pseudo_random_number_wrapper ) {
            printf
                ( "test_crypto_lib -> test_xrn_generate_confidential_pseudo_random_number_wrapper passed\n" );
        } else {
            printf
                ( "test_crypto_lib -> test_xrn_generate_confidential_pseudo_random_number_wrapper failed\n" );
        }

        if ( v_test_xrn_generate_confidential_pseudo_random_number_wrapper != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_encrypt_asymmetric_bytes = test_encrypt_asymmetric_bytes(  );
        error += v_test_encrypt_asymmetric_bytes;
        printf( "[%4d]", occ );
        if ( !v_test_encrypt_asymmetric_bytes ) {
            printf( "test_crypto_lib -> test_encrypt_asymmetric_bytes passed\n" );
        } else {
            printf( "test_crypto_lib -> test_encrypt_asymmetric_bytes failed\n" );
        }

        if ( v_test_encrypt_asymmetric_bytes != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_hash_str_file = test_hash_str_file(  );
        error += v_test_hash_str_file;
        printf( "[%4d]", occ );
        if ( !v_test_hash_str_file ) {
            printf( "test_crypto_lib -> test_hash_str_file passed\n" );
            fprintf( fp, "test_crypto_lib -> test_hash_str_file passed\n" );
        } else {
            printf( "test_crypto_lib -> test_hash_str_file failed\n" );
            fprintf( fp, "test_crypto_lib -> test_hash_str_file failed\n" );
        }

        if ( v_test_hash_str_file != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_encrypt_symmetric = test_encrypt_symmetric(  );
        error += v_test_encrypt_symmetric;
        printf( "[%4d]", occ );
        if ( !v_test_encrypt_symmetric ) {
            printf( "test_crypto_lib -> test_encrypt_symmetric passed\n" );
            fprintf( fp, "test_crypto_lib -> test_encrypt_symmetric passed\n" );
        } else {
            printf( "test_crypto_lib -> test_encrypt_symmetric failed\n" );
            fprintf( fp, "test_crypto_lib -> test_encrypt_symmetric failed\n" );
        }

        if ( v_test_encrypt_symmetric != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_encoder = test_encoder(  );
        error += v_test_encoder;
        printf( "[%4d]", occ );
        if ( !v_test_encoder ) {
            printf( "test_crypto_lib -> test_encoder passed\n" );
            fprintf( fp, "test_crypto_lib -> test_encoder passed\n" );
        } else {
            printf( "test_crypto_lib -> test_encoder failed\n" );
            fprintf( fp, "test_crypto_lib -> test_encoder failed\n" );
        }

        if ( v_test_encoder != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_encoder_bytes = test_encoder_bytes(  );
        error += v_test_encoder_bytes;
        printf( "[%4d]", occ );
        if ( !v_test_encoder_bytes ) {
            printf( "test_crypto_lib -> test_encoder_bytes passed\n" );
            fprintf( fp, "test_crypto_lib -> test_encoder_bytes passed\n" );
        } else {
            printf( "test_crypto_lib -> test_encoder_bytes failed\n" );
            fprintf( fp, "test_crypto_lib -> test_encoder_bytes failed\n" );
        }

        if ( v_test_encoder_bytes != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_encrypt_symmetric_bytes = test_encrypt_symmetric_bytes(  );
        error += v_test_encrypt_symmetric_bytes;
        printf( "[%4d]", occ );
        if ( !v_test_encrypt_symmetric_bytes ) {
            printf( "test_crypto_lib -> test_encrypt_symmetric_bytes passed\n" );
            fprintf( fp, "test_crypto_lib -> test_encrypt_symmetric_bytes passed\n" );
        } else {
            printf( "test_crypto_lib -> test_encrypt_symmetric_bytes failed\n" );
            fprintf( fp, "test_crypto_lib -> test_encrypt_symmetric_bytes failed\n" );
        }

        if ( v_test_encrypt_symmetric_bytes != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_loop_enc_stream = test_loop_enc_stream(  );
        error += v_test_loop_enc_stream;
        printf( "[%4d]", occ );
        if ( !v_test_loop_enc_stream ) {
            printf( "test_crypto_lib -> test_loop_enc_stream passed\n" );
            fprintf( fp, "test_crypto_lib -> test_loop_enc_stream passed\n" );
        } else {
            printf( "test_crypto_lib -> test_loop_enc_stream failed\n" );
            fprintf( fp, "test_crypto_lib -> test_loop_enc_stream failed\n" );
        }

        if ( v_test_loop_enc_stream != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_negative_test_signature_asym = negative_test_signature_asym(  );
        error += v_negative_test_signature_asym;
        printf( "[%4d]", occ );
        if ( !v_negative_test_signature_asym ) {
            printf( "test_crypto_lib -> negative_test_signature_asym passed\n" );
            fprintf( fp, "test_crypto_lib -> negative_test_signature_asym passed\n" );
        } else {
            printf( "test_crypto_lib -> negative_test_signature_asym failed\n" );
            fprintf( fp, "test_crypto_lib -> negative_test_signature_asym failed\n" );
        }

        if ( v_negative_test_signature_asym != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_negative_test_xrn_sign_asy_bytes = negative_test_xrn_sign_asy_bytes(  );
        error += v_negative_test_xrn_sign_asy_bytes;
        printf( "[%4d]", occ );
        if ( !v_negative_test_xrn_sign_asy_bytes ) {
            printf( "test_crypto_lib -> negative_test_xrn_sign_asy_bytes passed\n" );
        } else {
            printf( "test_crypto_lib -> negative_test_xrn_sign_asy_bytes failed\n" );
        }

        if ( v_negative_test_xrn_sign_asy_bytes != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_negative_test_signature_sym = negative_test_signature_sym(  );
        error += v_negative_test_signature_sym;
        printf( "[%4d]", occ );
        if ( !v_negative_test_signature_sym ) {
            printf( "test_crypto_lib -> negative_test_signature_sym passed\n" );
            fprintf( fp, "test_crypto_lib -> negative_test_signature_sym passed\n" );
        } else {
            printf( "test_crypto_lib -> negative_test_signature_sym failed\n" );
            fprintf( fp, "test_crypto_lib -> negative_test_signature_sym failed\n" );
        }

        if ( v_negative_test_signature_sym != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_negative_test_xrn_sign_sym_bytes = negative_test_xrn_sign_sym_bytes(  );
        error += v_negative_test_xrn_sign_sym_bytes;
        printf( "[%4d]", occ );
        if ( !v_negative_test_xrn_sign_sym_bytes ) {
            printf( "test_crypto_lib -> negative_test_xrn_sign_sym_bytes passed\n" );
            fprintf( fp, "test_crypto_lib -> negative_test_xrn_sign_sym_bytes passed\n" );
        } else {
            printf( "test_crypto_lib -> negative_test_xrn_sign_sym_bytes failed\n" );
            fprintf( fp, "test_crypto_lib -> negative_test_xrn_sign_sym_bytes failed\n" );
        }

        if ( v_negative_test_xrn_sign_sym_bytes != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_signature_sym = test_signature_sym(  );
        error += v_test_signature_sym;
        printf( "[%4d]", occ );
        if ( !v_test_signature_sym ) {
            printf( "test_crypto_lib -> test_signature_sym passed\n" );
            fprintf( fp, "test_crypto_lib -> test_signature_sym passed\n" );
        } else {
            printf( "test_crypto_lib -> test_signature_sym failed\n" );
            fprintf( fp, "test_crypto_lib -> test_signature_sym failed\n" );
        }

        if ( v_test_signature_sym != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_negative_test_verify_signature_bytes_proof = !negative_test_verify_signature_bytes_proof(  );
        error += v_negative_test_verify_signature_bytes_proof;
        printf( "[%4d]", occ );
        if ( !v_negative_test_verify_signature_bytes_proof ) {
            printf( "test_crypto_lib -> negative test_verify_signature_bytes_proof passed\n" );
            fprintf( fp, "test_crypto_lib -> negative test_verify_signature_bytes_proof passed\n" );
        } else {
            printf( "test_crypto_lib -> negative test_verify_signature_bytes_proof failed\n" );
            fprintf( fp, "test_crypto_lib -> negative test_verify_signature_bytes_proof failed\n" );
        }

        if ( v_negative_test_verify_signature_bytes_proof == 1 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_xrn_ring_sig_test_bytes = xrn_ring_sig_test_bytes(  );
        error += v_xrn_ring_sig_test_bytes;
        printf( "[%4d]", occ );
        if ( !v_xrn_ring_sig_test_bytes ) {
            printf( "test_crypto_lib -> xrn_ring_sig_test_bytes passed\n" );
        } else {
            printf( "test_crypto_lib -> xrn_ring_sig_test_bytes failed\n" );
        }

        if ( v_xrn_ring_sig_test_bytes != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_encrypt_symmetric_crc = test_encrypt_symmetric_crc(  );
        error += v_test_encrypt_symmetric_crc;
        printf( "[%4d]", occ );
        if ( !v_test_encrypt_symmetric_crc ) {
            printf( "test_crypto_lib -> negative test_encrypt_symmetric_crc passed\n" );
            fprintf( fp, "test_crypto_lib -> negative test_encrypt_symmetric_crc passed\n" );
        } else {
            printf( "test_crypto_lib -> negative test_encrypt_symmetric_crc failed\n" );
            fprintf( fp, "test_crypto_lib -> negative test_encrypt_symmetric_crc failed\n" );
        }

        if ( v_test_encrypt_symmetric_crc != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_key_exchange_wrapper = test_key_exchange_wrapper(  );
        error += v_test_key_exchange_wrapper;
        printf( "[%4d]", occ );
        if ( !v_test_key_exchange_wrapper ) {
            printf( "test_crypto_lib -> test_key_exchange_wrapper passed\n" );
            fprintf( fp, "test_crypto_lib -> test_key_exchange_wrapper passed\n" );
        } else {
            printf( "test_crypto_lib -> test_key_exchange_wrapper failed\n" );
            fprintf( fp, "test_crypto_lib -> test_key_exchange_wrapper failed\n" );
        }

        if ( v_test_key_exchange_wrapper != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_encrypt_asymmetric = test_encrypt_asymmetric(  );
        error += v_test_encrypt_asymmetric;
        printf( "[%4d]", occ );
        if ( !v_test_encrypt_asymmetric ) {
            printf( "test_crypto_lib -> test_encrypt_asymmetric passed\n" );
            fprintf( fp, "test_crypto_lib -> test_encrypt_asymmetric passed\n" );
        } else {
            printf( "test_crypto_lib -> test_encrypt_asymmetric failed\n" );
            fprintf( fp, "test_crypto_lib -> test_encrypt_asymmetric failed\n" );
        }

        if ( v_test_encrypt_asymmetric != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_matrix_compressed_key_permute = test_matrix_compressed_key_permute(  );
        error += v_test_matrix_compressed_key_permute;
        printf( "[%4d]", occ );
        if ( !v_test_matrix_compressed_key_permute ) {
            printf( "test_crypto_lib -> test_matrix_compressed_key_permute passed\n" );
            fprintf( fp, "test_crypto_lib -> test_matrix_compressed_key_permute passed\n" );
        } else {
            printf( "test_crypto_lib -> test_matrix_compressed_key_permute failed\n" );
            fprintf( fp, "test_crypto_lib -> test_matrix_compressed_key_permute failed\n" );
        }

        if ( v_test_matrix_compressed_key_permute != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_matrix_compressed_deterministic_permute = test_matrix_compressed_deterministic_permute(  );
        error += v_test_matrix_compressed_deterministic_permute;
        printf( "[%4d]", occ );
        if ( !v_test_matrix_compressed_deterministic_permute ) {
            printf( "test_crypto_lib -> test_matrix_compressed_deterministic_permute passed\n" );
            fprintf( fp, "test_crypto_lib -> test_matrix_compressed_deterministic_permute passed\n" );
        } else {
            printf( "test_crypto_lib -> test_matrix_compressed_deterministic_permute failed\n" );
            fprintf( fp, "test_crypto_lib -> test_matrix_compressed_deterministic_permute failed\n" );
        }

        if ( v_test_matrix_compressed_deterministic_permute != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_signature_asym = test_signature_asym(  );
        error += v_test_signature_asym;
        printf( "[%4d]", occ );
        if ( !v_test_signature_asym ) {
            printf( "test_crypto_lib -> test_signature_asym passed\n" );
            fprintf( fp, "test_crypto_lib -> test_signature_asym passed\n" );
        } else {
            printf( "test_crypto_lib -> test_signature_asym failed\n" );
            fprintf( fp, "test_crypto_lib -> test_signature_asym failed\n" );
        }

        if ( v_test_signature_asym != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_verify_signature_proof = test_verify_signature_proof(  );
        error += v_test_verify_signature_proof;
        printf( "[%4d]", occ );
        if ( !v_test_verify_signature_proof ) {
            printf( "test_crypto_lib -> test_verify_signature_proof passed\n" );
            fprintf( fp, "test_crypto_lib -> test_verify_signature_proof passed\n" );
        } else {
            printf( "test_crypto_lib -> test_verify_signature_proof failed\n" );
            fprintf( fp, "test_crypto_lib -> test_verify_signature_proof failed\n" );
        }

        if ( v_test_verify_signature_proof != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_verify_signature_bytes_proof = test_verify_signature_bytes_proof(  );
        error += v_test_verify_signature_bytes_proof;
        printf( "[%4d]", occ );
        if ( !v_test_verify_signature_bytes_proof ) {
            printf( "test_crypto_lib -> test_verify_signature_bytes_proof passed\n" );
            fprintf( fp, "test_crypto_lib -> test_verify_signature_bytes_proof passed\n" );
        } else {
            printf( "test_crypto_lib -> test_verify_signature_bytes_proof failed\n" );
            fprintf( fp, "test_crypto_lib -> test_verify_signature_bytes_proof failed\n" );
        }

        if ( v_test_verify_signature_bytes_proof != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_xrn_sign_asy_bytes = test_xrn_sign_asy_bytes(  );
        error += v_test_xrn_sign_asy_bytes;
        printf( "[%4d]", occ );
        if ( !v_test_xrn_sign_asy_bytes ) {
            printf( "test_crypto_lib -> test_xrn_sign_asy_bytes passed\n" );
            fprintf( fp, "test_crypto_lib -> test_xrn_sign_asy_bytes passed\n" );
        } else {
            printf( "test_crypto_lib -> test_xrn_sign_asy_bytes failed\n" );
            fprintf( fp, "test_crypto_lib -> test_xrn_sign_asy_bytes failed\n" );
        }

        if ( v_test_xrn_sign_asy_bytes != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_monovalent_key_verification = test_monovalent_key_verification(  );
        error += v_test_monovalent_key_verification;
        printf( "[%4d]", occ );
        if ( !v_test_monovalent_key_verification ) {
            printf( "test_crypto_lib -> test_monovalent_key_verification passed\n" );
            fprintf( fp, "test_crypto_lib -> test_monovalent_key_verification passed\n" );
        } else {
            printf( "test_crypto_lib -> test_monovalent_key_verification failed\n" );
            fprintf( fp, "test_crypto_lib -> test_monovalent_key_verification failed\n" );
        }

        if ( v_test_monovalent_key_verification != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_xrn_exchange_polyvalent_key = test_xrn_exchange_polyvalent_key(  );
        error += v_test_xrn_exchange_polyvalent_key;
        printf( "[%4d]", occ );
        if ( !v_test_xrn_exchange_polyvalent_key ) {
            printf( "test_crypto_lib -> test_xrn_exchange_polyvalent_key passed\n" );
            fprintf( fp, "test_crypto_lib -> test_xrn_exchange_polyvalent_key passed\n" );
        } else {
            printf( "test_crypto_lib -> test_xrn_exchange_polyvalent_key failed\n" );
            fprintf( fp, "test_crypto_lib -> test_xrn_exchange_polyvalent_key failed\n" );
        }

        if ( v_test_xrn_exchange_polyvalent_key != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CRYPTO FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CRYPTO FAILED SEED %ld \n", t );
#else
            fprintf( fp, "TEST_CRYPTO FAILED SEED %lld \n", t );
            sprintf( buff, "TEST_CRYPTO FAILED SEED %lld ", t );
#endif
            printf( "%s", buff );
        }

    }

    return error;

}

